diff --git a/calma/CalmaRead.c b/calma/CalmaRead.c index 6862ace2..62b2ae77 100644 --- a/calma/CalmaRead.c +++ b/calma/CalmaRead.c @@ -459,7 +459,7 @@ calmaParseUnits(void) */ void -CalmaReadError(char *format, ...) +CalmaReadError(const char *format, ...) { va_list args; OFFTYPE filepos; diff --git a/calma/calma.h b/calma/calma.h index d5f6363e..14e8f73b 100644 --- a/calma/calma.h +++ b/calma/calma.h @@ -65,7 +65,7 @@ extern bool CalmaWrite(CellDef *rootDef, FILE *f); extern void CalmaReadFile(FILETYPE file, char *filename); extern void CalmaTechInit(void); extern bool CalmaGenerateArray(FILE *f, TileType type, int llx, int lly, int pitch, int cols, int rows); -extern void CalmaReadError(char *format, ...); +extern void CalmaReadError(const char *format, ...) ATTR_FORMAT_PRINTF_1; /* C99 compat */ extern void calmaDelContacts(void); diff --git a/cif/CIFrdutils.c b/cif/CIFrdutils.c index f190a2ac..90e9c3fd 100644 --- a/cif/CIFrdutils.c +++ b/cif/CIFrdutils.c @@ -129,7 +129,7 @@ Plane *cifReadPlane; /* Plane into which to paint material /* VARARGS1 */ void -CIFReadError(char *format, ...) +CIFReadError(const char *format, ...) { va_list args; @@ -153,7 +153,7 @@ CIFReadError(char *format, ...) void -CIFReadWarning(char *format, ...) +CIFReadWarning(const char *format, ...) { va_list args; diff --git a/cif/CIFread.h b/cif/CIFread.h index c5400391..4b61bfa7 100644 --- a/cif/CIFread.h +++ b/cif/CIFread.h @@ -188,8 +188,8 @@ extern int CIFEdgeDirection(CIFPath *first, CIFPath *last); /* Variable argument procedures require complete prototype */ -extern void CIFReadError(char *format, ...); -extern void CIFReadWarning(char *format, ...); +extern void CIFReadError(const char *format, ...) ATTR_FORMAT_PRINTF_1; +extern void CIFReadWarning(const char *format, ...) ATTR_FORMAT_PRINTF_1; /* Variables shared by the CIF-reading modules, see CIFreadutils.c * for more details: diff --git a/drc/DRCtech.c b/drc/DRCtech.c index 995d166b..1f47b9c1 100644 --- a/drc/DRCtech.c +++ b/drc/DRCtech.c @@ -1020,7 +1020,7 @@ DRCTechAddRule(sectionName, argc, argv) char *argv[]; { int which, distance, mdist; - char *fmt; + const char *fmt; static const struct { const char *rk_keyword; /* Initial keyword */ diff --git a/ext2sim/ext2sim.c b/ext2sim/ext2sim.c index 3252bbbb..6ca3dc11 100644 --- a/ext2sim/ext2sim.c +++ b/ext2sim/ext2sim.c @@ -1603,7 +1603,7 @@ int simnodeVisit(node, res, cap) EFNodeName *nn; HierName *hierName; bool isGlob; - char *fmt; + const char *fmt; EFAttr *ap; if (esDevNodesOnly && node->efnode_client == (ClientData) NULL) diff --git a/ext2spice/ext2hier.c b/ext2spice/ext2hier.c index 1bf292f0..7f090516 100644 --- a/ext2spice/ext2hier.c +++ b/ext2spice/ext2hier.c @@ -1423,7 +1423,7 @@ spcnodeHierVisit(hc, node, res, cap) EFNodeName *nn; HierName *hierName; bool isConnected = FALSE; - char *fmt, *nsn; + const char *fmt, *nsn; EFAttr *ap; if (node->efnode_client) diff --git a/ext2spice/ext2spice.c b/ext2spice/ext2spice.c index 7bd1693c..d7efe11a 100644 --- a/ext2spice/ext2spice.c +++ b/ext2spice/ext2spice.c @@ -3669,7 +3669,8 @@ spcnodeVisit(node, res, cap) EFNodeName *nn; HierName *hierName; bool isConnected = FALSE; - char *fmt, *nsn; + const char *fmt; + char *nsn; EFAttr *ap; if (node->efnode_client) @@ -3731,7 +3732,7 @@ nodeVisitDebug(node, res, cap) { EFNodeName *nn; HierName *hierName; - char *fmt, *nsn; + char *nsn; EFAttr *ap; hierName = (HierName *) node->efnode_name->efnn_hier; diff --git a/extflat/EFerr.c b/extflat/EFerr.c index 280fb9ad..c69d3bf5 100644 --- a/extflat/EFerr.c +++ b/extflat/EFerr.c @@ -64,7 +64,7 @@ extern int Tcl_printf(); */ void -efReadError(char *fmt, ...) +efReadError(const char *fmt, ...) { va_list args; diff --git a/extflat/extflat.h b/extflat/extflat.h index 5bbf6612..d02830c1 100644 --- a/extflat/extflat.h +++ b/extflat/extflat.h @@ -390,7 +390,7 @@ extern int efHierSrArray(); extern int efHierSrUses(); extern int efHierVisitDevs(); extern EFNode *efNodeMerge(); -extern void efReadError(); +extern void efReadError(const char *fmt, ...) ATTR_FORMAT_PRINTF_1; extern int efReadLine(); extern bool efSymAdd(); extern bool efSymAddFile(); diff --git a/graphics/grOGL1.c b/graphics/grOGL1.c index 9540c9d8..4b3b5acd 100644 --- a/graphics/grOGL1.c +++ b/graphics/grOGL1.c @@ -267,6 +267,7 @@ GrOGLInit() { TxError("No suitable visual!\n"); MainExit(1); + ATTR_UNREACHABLE; } } grXscrn = grVisualInfo->screen; diff --git a/lef/lefInt.h b/lef/lefInt.h index 21e2c88b..521867e5 100644 --- a/lef/lefInt.h +++ b/lef/lefInt.h @@ -162,8 +162,8 @@ void LefReadLayerSection(); LefMapping *defMakeInverseLayerMap(); -void LefError(int, char *, ...); /* Variable argument procedure requires */ - /* parameter list. */ +/* Variable argument procedure requires parameter list. */ +void LefError(int, const char *, ...) ATTR_FORMAT_PRINTF_2; /* C99 compat */ extern void LefRead(); diff --git a/lef/lefRead.c b/lef/lefRead.c index 9b9d3c45..b0acca12 100644 --- a/lef/lefRead.c +++ b/lef/lefRead.c @@ -306,7 +306,7 @@ LefNextToken(f, ignore_eol) */ void -LefError(int type, char *fmt, ...) +LefError(int type, const char *fmt, ...) { static int errors = 0, warnings = 0, messages = 0; va_list args; diff --git a/tcltk/tclmagic.c b/tcltk/tclmagic.c index 57de6176..4363f7e1 100644 --- a/tcltk/tclmagic.c +++ b/tcltk/tclmagic.c @@ -1028,7 +1028,7 @@ TxFlush() /*--------------------------------------------------------------*/ int -Tcl_printf(FILE *f, char *fmt, va_list args_in) +Tcl_printf(FILE *f, const char *fmt, va_list args_in) { va_list args; static char outstr[128] = "puts -nonewline std"; diff --git a/textio/textio.h b/textio/textio.h index aa3e5fff..b7c6c1c2 100644 --- a/textio/textio.h +++ b/textio/textio.h @@ -68,10 +68,10 @@ extern void TxUseMore(); extern void TxStopMore(); /* printing procedures with variable arguments lists */ -extern void TxError(char *, ...); -extern void TxErrorV(char *, va_list args); -extern void TxPrintf(char *, ...); -extern char *TxPrintString(char *, ...); +extern void TxError(const char *, ...) ATTR_FORMAT_PRINTF_1; +extern void TxErrorV(const char *, va_list args); +extern void TxPrintf(const char *, ...) ATTR_FORMAT_PRINTF_1; +extern char *TxPrintString(const char *, ...) ATTR_FORMAT_PRINTF_1; /* input procedures */ extern char *TxGetLinePrompt(); diff --git a/textio/textioInt.h b/textio/textioInt.h index 83de8c62..7075a979 100644 --- a/textio/textioInt.h +++ b/textio/textioInt.h @@ -52,7 +52,7 @@ extern bool TxGetInputEvent(); /* Routines with variable argument lists */ -extern void txFprintfBasic(FILE *, ...); +extern void txFprintfBasic(FILE *, const char *fmt, ...) ATTR_FORMAT_PRINTF_2; /* C99 compat */ void txCommandsInit(); diff --git a/textio/txOutput.c b/textio/txOutput.c index 7aec132e..2d1ccf02 100644 --- a/textio/txOutput.c +++ b/textio/txOutput.c @@ -76,13 +76,11 @@ static bool txPrintFlag = TRUE; */ void -txFprintfBasic(FILE *f, ...) +txFprintfBasic(FILE *f, const char *fmt, ...) { va_list args; - char *fmt; - va_start(args, f); - fmt = va_arg(args, char *); + va_start(args, fmt); Vfprintf(f, fmt, args); va_end(args); } @@ -110,7 +108,7 @@ txFprintfBasic(FILE *f, ...) */ void -TxPrintf(char *fmt, ...) +TxPrintf(const char *fmt, ...) { va_list args; FILE *f; @@ -161,7 +159,7 @@ TxPrintf(char *fmt, ...) */ char * -TxPrintString(char *fmt, ...) +TxPrintString(const char *fmt, ...) { va_list args; static char *outstr = NULL; @@ -302,7 +300,7 @@ TxFlush() */ void -TxError(char *fmt, ...) { +TxError(const char *fmt, ...) { va_list args; va_start(args, fmt); TxErrorV(fmt, args); @@ -310,7 +308,7 @@ TxError(char *fmt, ...) { } void -TxErrorV(char *fmt, va_list args) +TxErrorV(const char *fmt, va_list args) { FILE *f; @@ -467,7 +465,7 @@ TxStopMore() #ifdef NEED_VFPRINTF int -vfprintf(FILR *iop, char *fmt, va_list args_in) +vfprintf(FILR *iop, const char *fmt, va_list args_in) { va_list ap; int len; diff --git a/utils/LIBtextio.c b/utils/LIBtextio.c index e8fc279d..ef42e225 100644 --- a/utils/LIBtextio.c +++ b/utils/LIBtextio.c @@ -96,7 +96,7 @@ TxFlush() */ void -TxError(char *fmt, ...) +TxError(const char *fmt, ...) { va_list ap; @@ -126,7 +126,7 @@ TxError(char *fmt, ...) */ void -TxPrintf(char *fmt, ...) +TxPrintf(const char *fmt, ...) { va_list ap; diff --git a/utils/geometry.c b/utils/geometry.c index b5b06503..7b4a4924 100644 --- a/utils/geometry.c +++ b/utils/geometry.c @@ -403,7 +403,7 @@ GeoNameToPos(name, manhattan, verbose) {"west", GEO_WEST, TRUE}, {0} }; - char *fmt; + const char *fmt; const struct pos *pp; int pos; diff --git a/utils/magic.h b/utils/magic.h index 0dcda8e9..77fd57ad 100644 --- a/utils/magic.h +++ b/utils/magic.h @@ -168,6 +168,36 @@ extern char AbortMessage[]; #define PaLockZOpen PaLockOpen #endif +/* ------------ modern compiler support -------------------------------- */ + +#if defined(__GNUC__) || defined(__clang__) + #define ATTR_FORMAT_PRINTF_1 __attribute__((format (printf,1,2))) + #define ATTR_FORMAT_PRINTF_2 __attribute__((format (printf,2,3))) + #define ATTR_SENTINEL __attribute__ ((sentinel)) + #define ATTR_UNREACHABLE __builtin_unreachable() + #define ATTR_NORETURN __attribute__((noreturn)) + #define __unused__(x) x __attribute__((unused)) + + #define ANALYSER_CSTRING(n) __attribute__((null_terminated_string_arg(n))) + #define ANALYSER_FD_ARG(fd) __attribute__((fd_arg(fd))) + #define ANALYSER_MALLOC(dealloc, idx) __attribute__((malloc, malloc(dealloc, idx))) + #define ANALYSER_NONNULL(n...) __attribute__((nonnull(n))) + #define ANALYSER_RETURNS_NONNULL __attribute__((returns_nonnull)) +#else + #define ATTR_FORMAT_PRINTF_1 /* */ + #define ATTR_FORMAT_PRINTF_2 /* */ + #define ATTR_SENTINEL /* */ + #define ATTR_UNREACHABLE /* */ + #define ATTR_NORETURN /* */ + #define __unused__(x) x + + #define ANALYSER_CSTRING(n) /* */ + #define ANALYSER_FD_ARG(fd) /* */ + #define ANALYSER_MALLOC(dealloc, idx) /* */ + #define ANALYSER_NONNULL(n...) /* */ + #define ANALYSER_RETURNS_NONNULL /* */ +#endif + /* ---------------- Start of Machine Configuration Section ----------------- */ /* ------- Configuration: Handle Missing Routines/Definitions ------- */ diff --git a/utils/main.h b/utils/main.h index 26f4d00d..bb5acc55 100644 --- a/utils/main.h +++ b/utils/main.h @@ -92,7 +92,7 @@ extern Transform RootToEditTransform; /* global procedures */ -extern void MainExit(int); /* a way of exiting that cleans up after itself */ +extern void MainExit(int) ATTR_NORETURN; /* a way of exiting that cleans up after itself */ extern void magicMain(); /* C99 compat */ diff --git a/utils/tech.c b/utils/tech.c index 20fbcbb6..ac470b72 100644 --- a/utils/tech.c +++ b/utils/tech.c @@ -856,7 +856,7 @@ TechPrintLine() } void -TechError(char *fmt, ...) +TechError(const char *fmt, ...) { va_list args; diff --git a/utils/tech.h b/utils/tech.h index e2cd8ff0..c94c0e80 100644 --- a/utils/tech.h +++ b/utils/tech.h @@ -51,7 +51,7 @@ extern bool TechOverridesDefault; /* Set TRUE if technology was specified on /* ----------------- Exported procedures ---------------- */ -extern void TechError(char *, ...); +extern void TechError(const char *, ...) ATTR_FORMAT_PRINTF_1; extern void TechAddClient(); extern void TechAddAlias();