From bda776ec021344013df2d7b3480ca141e98e3a83 Mon Sep 17 00:00:00 2001 From: Rob Taylor Date: Fri, 18 Aug 2023 18:28:57 +0100 Subject: [PATCH] Make sprints safe in lefdef --- lefdef/src/def/def/def.y | 198 ++++++++++---------------- lefdef/src/def/def/def_keywords.cpp | 56 +++----- lefdef/src/def/def/defiNonDefault.cpp | 110 ++++++++------ lefdef/src/def/def/defiPinProp.cpp | 30 ++-- lefdef/src/def/def/defiRegion.cpp | 50 ++++--- lefdef/src/def/def/defiRowTrack.cpp | 30 ++-- lefdef/src/def/def/defiSlot.cpp | 20 +-- lefdef/src/def/defzlib/CMakeLists.txt | 2 +- lefdef/src/lef/lef/lef_keywords.cpp | 72 ++++++---- lefdef/src/lef/lefzlib/CMakeLists.txt | 2 +- 10 files changed, 279 insertions(+), 291 deletions(-) diff --git a/lefdef/src/def/def/def.y b/lefdef/src/def/def/def.y index 992b489a..a0ddc1c2 100644 --- a/lefdef/src/def/def/def.y +++ b/lefdef/src/def/def/def.y @@ -57,6 +57,7 @@ %{ #include +#include #include #include "defrReader.hpp" #include "defiUser.hpp" @@ -99,8 +100,7 @@ BEGIN_LEFDEF_PARSER_NAMESPACE #define CHKPROPTYPE(propType, propName, name) \ if (propType == 'N') { \ - defData->warningMsg = (char*)malloc(strlen(propName)+strlen(name)+40); \ - sprintf(defData->warningMsg, "The PropName %s is not defined for %s.", \ + asprintf(&defData->warningMsg, "The PropName %s is not defined for %s.",\ propName, name); \ defData->defWarning(7010, defData->warningMsg); \ free(defData->warningMsg); \ @@ -221,11 +221,12 @@ version_stmt: // empty { defData->VersionNum = defrData::convert_defname2num($3); if (defData->VersionNum > CURRENT_VERSION) { - char temp[300]; - sprintf(temp, + char *temp; + asprintf(&temp, "The execution has been stopped because the DEF parser %.1f does not support DEF file with version %s.\nUpdate your DEF file to version 5.8 or earlier.", CURRENT_VERSION, $3); defData->defError(6503, temp); + free(temp); return 1; } if (defData->callbacks->VersionStrCbk) { @@ -316,9 +317,10 @@ end_design: K_END K_DESIGN return 1; if (!defData->hasVer) { - char temp[300]; - sprintf(temp, "No VERSION statement found, using the default value %2g.", defData->VersionNum); + char *temp; + asprintf(&temp, "No VERSION statement found, using the default value %2g.", defData->VersionNum); defData->defWarning(7012, temp); + free(temp); } if (!defData->hasNameCase && defData->VersionNum < 5.6) defData->defWarning(7013, "The DEF file is invalid if NAMESCASESENSITIVE is undefined.\nNAMESCASESENSITIVE is a mandatory statement in the DEF file with version 5.6 and earlier.\nTo define the NAMESCASESENSITIVE statement, refer to the LEF/DEF 5.5 and earlier Language Reference manual."); @@ -450,8 +452,7 @@ property_def: K_DESIGN {defData->dumb_mode = 1; defData->no_num = 1; defData->Pr { if (defData->VersionNum < 5.6) { if (defData->nonDefaultWarnings++ < defData->settings->NonDefaultWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The NONDEFAULTRULE statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6505, defData->defMsg); free(defData->defMsg); @@ -654,8 +655,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The NETEXPR statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6506, defData->defMsg); free(defData->defMsg); @@ -675,8 +675,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The SUPPLYSENSITIVITY statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6507, defData->defMsg); free(defData->defMsg); @@ -695,8 +694,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The GROUNDSENSITIVITY statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6508, defData->defMsg); free(defData->defMsg); @@ -719,8 +717,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(10000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The PORT in PINS is available in version 5.7 or later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6555, defData->defMsg); free(defData->defMsg); @@ -759,8 +756,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The POLYGON statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6509, defData->defMsg); free(defData->defMsg); @@ -795,8 +791,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The PIN VIA statement is available in version 5.7 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6556, defData->defMsg); free(defData->defMsg); @@ -833,8 +828,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The ANTENNAPINPARTIALMETALAREA statement is available in version 5.4 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6510, defData->defMsg); free(defData->defMsg); @@ -851,8 +845,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The ANTENNAPINPARTIALMETALSIDEAREA statement is available in version 5.4 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6511, defData->defMsg); free(defData->defMsg); @@ -869,8 +862,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The ANTENNAPINGATEAREA statement is available in version 5.4 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6512, defData->defMsg); free(defData->defMsg); @@ -887,8 +879,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The ANTENNAPINDIFFAREA statement is available in version 5.4 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6513, defData->defMsg); free(defData->defMsg); @@ -905,8 +896,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The ANTENNAPINMAXAREACAR statement is available in version 5.4 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6514, defData->defMsg); free(defData->defMsg); @@ -924,8 +914,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The ANTENNAPINMAXSIDEAREACAR statement is available in version 5.4 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6515, defData->defMsg); free(defData->defMsg); @@ -942,8 +931,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The ANTENNAPINPARTIALCUTAREA statement is available in version 5.4 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6516, defData->defMsg); free(defData->defMsg); @@ -960,8 +948,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The ANTENNAPINMAXCUTCAR statement is available in version 5.4 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6517, defData->defMsg); free(defData->defMsg); @@ -978,8 +965,7 @@ pin_option: '+' K_SPECIAL if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The ANTENNAMODEL statement is available in version 5.5 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6518, defData->defMsg); free(defData->defMsg); @@ -1033,8 +1019,7 @@ pin_layer_spacing_opt: // empty if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The SPACING statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6519, defData->defMsg); free(defData->defMsg); @@ -1056,8 +1041,7 @@ pin_layer_spacing_opt: // empty if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "DESIGNRULEWIDTH statement is a version 5.6 and later syntax.\nYour def file is defined with version %g", defData->VersionNum); defData->defError(6520, defData->defMsg); free(defData->defMsg); @@ -1081,8 +1065,7 @@ pin_poly_spacing_opt: // empty if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "SPACING statement is a version 5.6 and later syntax.\nYour def file is defined with version %g", defData->VersionNum); defData->defError(6521, defData->defMsg); free(defData->defMsg); @@ -1104,8 +1087,7 @@ pin_poly_spacing_opt: // empty if (defData->callbacks->PinCbk || defData->callbacks->PinExtCbk) { if ((defData->pinWarnings++ < defData->settings->PinWarnings) && (defData->pinWarnings++ < defData->settings->PinExtWarnings)) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The DESIGNRULEWIDTH statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6520, defData->defMsg); free(defData->defMsg); @@ -1213,8 +1195,7 @@ row_do_option: // empty if (defData->VersionNum < 5.6) { if (defData->callbacks->RowCbk) { if (defData->rowWarnings++ < defData->settings->RowWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf(defData->defMsg, + asprintf(&defData->defMsg, "The DO statement in the ROW statement with the name %s has invalid syntax.\nThe valid syntax is \"DO numX BY 1 STEP spaceX 0 | DO 1 BY numY STEP 0 spaceY\".\nSpecify the valid syntax and try again.", defData->rowName); defData->defWarning(7018, defData->defMsg); free(defData->defMsg); @@ -1267,7 +1248,7 @@ row_prop : T_STRING NUMBER propTp = defData->session->RowProp.propType($1); CHKPROPTYPE(propTp, $1, "ROW"); // For backword compatibility, also set the string value - sprintf(str, "%g", $2); + snprintf(str, 24, "%g", $2); defData->Row.addNumProperty($1, $2, str, propTp); } } @@ -1301,8 +1282,7 @@ tracks_rule: track_start NUMBER if (($5 <= 0) && (defData->VersionNum >= 5.4)) { if (defData->callbacks->TrackCbk) if (defData->trackWarnings++ < defData->settings->TrackWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The DO number %g in TRACK is invalid.\nThe number value has to be greater than 0. Specify the valid syntax and try again.", $5); defData->defError(6525, defData->defMsg); free(defData->defMsg); @@ -1311,8 +1291,7 @@ tracks_rule: track_start NUMBER if ($7 < 0) { if (defData->callbacks->TrackCbk) if (defData->trackWarnings++ < defData->settings->TrackWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The STEP number %g in TRACK is invalid.\nThe number value has to be greater than 0. Specify the valid syntax and try again.", $7); defData->defError(6526, defData->defMsg); free(defData->defMsg); @@ -1372,8 +1351,7 @@ gcellgrid: K_GCELLGRID track_type NUMBER if ($5 <= 0) { if (defData->callbacks->GcellGridCbk) if (defData->gcellGridWarnings++ < defData->settings->GcellGridWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The DO number %g in GCELLGRID is invalid.\nThe number value has to be greater than 0. Specify the valid syntax and try again.", $5); defData->defError(6527, defData->defMsg); free(defData->defMsg); @@ -1382,8 +1360,7 @@ gcellgrid: K_GCELLGRID track_type NUMBER if ($7 < 0) { if (defData->callbacks->GcellGridCbk) if (defData->gcellGridWarnings++ < defData->settings->GcellGridWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The STEP number %g in GCELLGRID is invalid.\nThe number value has to be greater than 0. Specify the valid syntax and try again.", $7); defData->defError(6528, defData->defMsg); free(defData->defMsg); @@ -1445,8 +1422,7 @@ layer_stmt: '+' K_RECT {defData->dumb_mode = 1;defData->no_num = 1; } T_STRING m if (defData->VersionNum < 5.6) { if (defData->callbacks->ViaCbk) { if (defData->viaWarnings++ < defData->settings->ViaWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The POLYGON statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6509, defData->defMsg); free(defData->defMsg); @@ -1487,8 +1463,7 @@ layer_stmt: '+' K_RECT {defData->dumb_mode = 1;defData->no_num = 1; } T_STRING m if (defData->VersionNum < 5.6) { if (defData->callbacks->ViaCbk) { if (defData->viaWarnings++ < defData->settings->ViaWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The VIARULE statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6557, defData->defMsg); free(defData->defMsg); @@ -1675,7 +1650,7 @@ region_prop : T_STRING NUMBER // We will use a temporary string to store the number. // The string space is borrowed from the ring buffer // in the lexer. - sprintf(str, "%g", $2); + snprintf(str, 24, "%g", $2); defData->Region.addNumProperty($1, $2, str, propTp); } } @@ -1707,8 +1682,7 @@ comps_maskShift_section : K_COMPSMASKSHIFT layer_statement ';' { if (defData->VersionNum < 5.8) { if (defData->componentWarnings++ < defData->settings->ComponentWarnings) { - defData->defMsg = (char*)malloc(10000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The MASKSHIFT statement is available in version 5.8 and later.\nHowever, your DEF file is defined with version %g", defData->VersionNum); defData->defError(7415, defData->defMsg); free(defData->defMsg); @@ -1864,8 +1838,7 @@ comp_halo: '+' K_HALO // 5.7 if (defData->VersionNum < 5.6) { if (defData->callbacks->ComponentCbk) { if (defData->componentWarnings++ < defData->settings->ComponentWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The HALO statement is a version 5.6 and later syntax.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6529, defData->defMsg); free(defData->defMsg); @@ -1887,8 +1860,7 @@ halo_soft: // 5.7 if (defData->VersionNum < 5.7) { if (defData->callbacks->ComponentCbk) { if (defData->componentWarnings++ < defData->settings->ComponentWarnings) { - defData->defMsg = (char*)malloc(10000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The HALO SOFT is available in version 5.7 or later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6550, defData->defMsg); free(defData->defMsg); @@ -1907,8 +1879,7 @@ comp_routehalo: '+' K_ROUTEHALO NUMBER { defData->dumb_mode = 2; defData->no_num if (defData->VersionNum < 5.7) { if (defData->callbacks->ComponentCbk) { if (defData->componentWarnings++ < defData->settings->ComponentWarnings) { - defData->defMsg = (char*)malloc(10000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The ROUTEHALO is available in version 5.7 or later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6551, defData->defMsg); free(defData->defMsg); @@ -1937,7 +1908,7 @@ comp_prop: T_STRING NUMBER char* str = defData->ringCopy(" "); propTp = defData->session->CompProp.propType($1); CHKPROPTYPE(propTp, $1, "COMPONENT"); - sprintf(str, "%g", $2); + snprintf(str, 24, "%g", $2); defData->Component.addNumProperty($1, $2, str, propTp); } } @@ -2166,8 +2137,7 @@ net_option: '+' net_type if (defData->VersionNum < 5.5) { if (defData->callbacks->NetCbk) { if (defData->netWarnings++ < defData->settings->NetWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The FIXEDBUMP statement is available in version 5.5 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6530, defData->defMsg); free(defData->defMsg); @@ -2183,8 +2153,7 @@ net_option: '+' net_type if (defData->VersionNum < 5.5) { if (defData->callbacks->NetCbk) { if (defData->netWarnings++ < defData->settings->NetWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The FREQUENCY statement is a version 5.5 and later syntax.\nHowever, your DEF file is defined with version %g", defData->VersionNum); defData->defError(6558, defData->defMsg); free(defData->defMsg); @@ -2330,7 +2299,7 @@ net_prop: T_STRING NUMBER char* str = defData->ringCopy(" "); propTp = defData->session->NetProp.propType($1); CHKPROPTYPE(propTp, $1, "NET"); - sprintf(str, "%g", $2); + snprintf(str, 24, "%g", $2); defData->Net.addNumProp($1, $2, str, propTp); } } @@ -2452,8 +2421,7 @@ virtual_statement : if (defData->VersionNum < 5.8) { if (defData->callbacks->SNetCbk) { if (defData->sNetWarnings++ < defData->settings->SNetWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The VIRTUAL statement is available in version 5.8 and later.\nHowever, your DEF file is defined with version %g", defData->VersionNum); defData->defError(6536, defData->defMsg); free(defData->defMsg); @@ -2469,8 +2437,7 @@ rect_statement : if (defData->VersionNum < 5.8) { if (defData->callbacks->SNetCbk) { if (defData->sNetWarnings++ < defData->settings->SNetWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The RECT statement is available in version 5.8 and later.\nHowever, your DEF file is defined with version %g", defData->VersionNum); defData->defError(6536, defData->defMsg); free(defData->defMsg); @@ -2560,8 +2527,7 @@ path_item: if (defData->NeedPathData && defData->callbacks->SNetCbk) { if (defData->netWarnings++ < defData->settings->NetWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The VIA DO statement is available in version 5.5 and later.\nHowever, your DEF file is defined with version %g", defData->VersionNum); defData->defError(6532, defData->defMsg); free(defData->defMsg); @@ -2594,8 +2560,7 @@ path_item: if (defData->NeedPathData && defData->callbacks->SNetCbk) { if (defData->netWarnings++ < defData->settings->NetWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The VIA DO statement is available in version 5.5 and later.\nHowever, your DEF file is defined with version %g", defData->VersionNum); defData->defError(6532, defData->defMsg); CHKERR(); @@ -2802,8 +2767,7 @@ opt_style: K_STYLE NUMBER if (defData->NeedPathData && (defData->callbacks->NetCbk || defData->callbacks->SNetCbk)) { if (defData->netWarnings++ < defData->settings->NetWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The STYLE statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g", defData->VersionNum); defData->defError(6534, defData->defMsg); free(defData->defMsg); @@ -2830,8 +2794,7 @@ opt_shape_style: if (defData->NeedPathData && ((defData->callbacks->NetCbk && (defData->netOsnet==1)) || (defData->callbacks->SNetCbk && (defData->netOsnet==2)))) { if (defData->netWarnings++ < defData->settings->NetWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The STYLE statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g", defData->VersionNum); defData->defError(6534, defData->defMsg); free(defData->defMsg); @@ -2870,8 +2833,7 @@ shape_type: K_RING if (defData->VersionNum < 5.7) { if (defData->NeedPathData) { if (defData->fillWarnings++ < defData->settings->FillWarnings) { - defData->defMsg = (char*)malloc(10000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The FILLWIREOPC is available in version 5.7 or later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6552, defData->defMsg); free(defData->defMsg); @@ -2914,8 +2876,7 @@ snet_other_option: '+' net_type defData->specialWire_routeStatus = $2; } else { if (defData->callbacks->SNetCbk) { // PCR 902306 - defData->defMsg = (char*)malloc(1024); - sprintf(defData->defMsg, "The SPECIAL NET statement, with type %s, does not have any net statement defined.\nThe DEF parser will ignore this statemnet.", $2); + asprintf(&defData->defMsg, "The SPECIAL NET statement, with type %s, does not have any net statement defined.\nThe DEF parser will ignore this statemnet.", $2); defData->defWarning(7023, defData->defMsg); free(defData->defMsg); } @@ -2965,8 +2926,7 @@ snet_other_option: '+' net_type if (defData->VersionNum < 5.6) { if (defData->callbacks->SNetCbk) { if (defData->sNetWarnings++ < defData->settings->SNetWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The POLYGON statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g", defData->VersionNum); defData->defError(6535, defData->defMsg); free(defData->defMsg); @@ -3006,8 +2966,7 @@ snet_other_option: '+' net_type if (defData->VersionNum < 5.6) { if (defData->callbacks->SNetCbk) { if (defData->sNetWarnings++ < defData->settings->SNetWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The RECT statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g", defData->VersionNum); defData->defError(6536, defData->defMsg); free(defData->defMsg); @@ -3039,8 +2998,7 @@ snet_other_option: '+' net_type if (defData->VersionNum < 5.8) { if (defData->callbacks->SNetCbk) { if (defData->sNetWarnings++ < defData->settings->SNetWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The VIA statement is available in version 5.8 and later.\nHowever, your DEF file is defined with version %g", defData->VersionNum); defData->defError(6536, defData->defMsg); free(defData->defMsg); @@ -3123,8 +3081,7 @@ shield_layer: // PCR 902306 { if (defData->callbacks->SNetCbk) { if (defData->VersionNum < 5.8) { - defData->defMsg = (char*)malloc(1024); - sprintf(defData->defMsg, "The SPECIAL NET SHIELD statement doesn't have routing points definition.\nWill be ignored."); + asprintf(&defData->defMsg, "The SPECIAL NET SHIELD statement doesn't have routing points definition.\nWill be ignored."); defData->defWarning(7025, defData->defMsg); free(defData->defMsg); } else { // CCR 1244433 @@ -3206,8 +3163,7 @@ snet_voltage: '+' K_VOLTAGE { defData->dumb_mode = 1; defData->no_num = 1; } T_ } else { if (defData->callbacks->SNetCbk) { if (defData->sNetWarnings++ < defData->settings->SNetWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The value %s for statement VOLTAGE is invalid. The value can only be integer.\nSpecify a valid value in units of millivolts", $4); defData->defError(6537, defData->defMsg); free(defData->defMsg); @@ -3237,7 +3193,7 @@ snet_prop: T_STRING NUMBER propTp = defData->session->SNetProp.propType($1); CHKPROPTYPE(propTp, $1, "SPECIAL NET"); // For backword compatibility, also set the string value - sprintf(str, "%g", $2); + snprintf(str, 24, "%g", $2); defData->Net.addNumProp($1, $2, str, propTp); } } @@ -3438,7 +3394,7 @@ group_prop : T_STRING NUMBER char* str = defData->ringCopy(" "); propTp = defData->session->GroupProp.propType($1); CHKPROPTYPE(propTp, $1, "GROUP"); - sprintf(str, "%g", $2); + snprintf(str, 24, "%g", $2); defData->Group.addNumProperty($1, $2, str, propTp); } } @@ -3712,8 +3668,7 @@ scan_member: '+' K_START {defData->dumb_mode = 2; defData->no_num = 2;} T_STRING if (defData->VersionNum < 5.5) { if (defData->callbacks->ScanchainCbk) { if (defData->scanchainWarnings++ < defData->settings->ScanchainWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The PARTITION statement is available in version 5.5 and later.\nHowever, your DEF file is defined with version %g", defData->VersionNum); defData->defError(6538, defData->defMsg); free(defData->defMsg); @@ -4387,7 +4342,7 @@ pin_prop_name_value : T_STRING NUMBER char* str = defData->ringCopy(" "); propTp = defData->session->CompPinProp.propType($1); CHKPROPTYPE(propTp, $1, "PINPROPERTIES"); - sprintf(str, "%g", $2); + snprintf(str, 24, "%g", $2); defData->PinProp.addNumProperty($1, $2, str, propTp); } } @@ -4478,8 +4433,7 @@ layer_blockage_rule: '+' K_SPACING NUMBER if (defData->VersionNum < 5.6) { if (defData->callbacks->BlockageCbk) { if (defData->blockageWarnings++ < defData->settings->BlockageWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The SPACING statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g", defData->VersionNum); defData->defError(6540, defData->defMsg); free(defData->defMsg); @@ -4618,8 +4572,7 @@ comp_blockage_rule: if (defData->VersionNum < 5.7) { if (defData->callbacks->BlockageCbk) { if (defData->blockageWarnings++ < defData->settings->BlockageWarnings) { - defData->defMsg = (char*)malloc(10000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The EXCEPTPGNET is available in version 5.7 or later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6549, defData->defMsg); free(defData->defMsg); @@ -4692,8 +4645,7 @@ placement_comp_rule: // empty if (defData->VersionNum < 5.7) { if (defData->callbacks->BlockageCbk) { if (defData->blockageWarnings++ < defData->settings->BlockageWarnings) { - defData->defMsg = (char*)malloc(10000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The PLACEMENT SOFT is available in version 5.7 or later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6547, defData->defMsg); free(defData->defMsg); @@ -4726,8 +4678,7 @@ placement_comp_rule: // empty if (defData->VersionNum < 5.7) { if (defData->callbacks->BlockageCbk) { if (defData->blockageWarnings++ < defData->settings->BlockageWarnings) { - defData->defMsg = (char*)malloc(10000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The PARTIAL is available in version 5.7 or later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6548, defData->defMsg); free(defData->defMsg); @@ -4903,8 +4854,7 @@ geom_fill: K_RECT pt pt if (defData->callbacks->FillCbk) defData->Fill.addPolygon(&defData->Geometries); } else { - defData->defMsg = (char*)malloc(10000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "POLYGON statement in FILLS LAYER is a version 5.6 and later syntax.\nYour def file is defined with version %g.", defData->VersionNum); defData->defError(6564, defData->defMsg); free(defData->defMsg); @@ -4926,8 +4876,7 @@ fill_layer_opc: if (defData->VersionNum < 5.7) { if (defData->callbacks->FillCbk) { if (defData->fillWarnings++ < defData->settings->FillWarnings) { - defData->defMsg = (char*)malloc(10000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The LAYER OPC is available in version 5.7 or later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6553, defData->defMsg); free(defData->defMsg); @@ -4964,8 +4913,7 @@ fill_via_opc: if (defData->VersionNum < 5.7) { if (defData->callbacks->FillCbk) { if (defData->fillWarnings++ < defData->settings->FillWarnings) { - defData->defMsg = (char*)malloc(10000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The VIA OPC is available in version 5.7 or later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6554, defData->defMsg); free(defData->defMsg); @@ -5007,8 +4955,7 @@ nondefault_start: K_NONDEFAULTRULES NUMBER ';' if (defData->VersionNum < 5.6) { if (defData->callbacks->NonDefaultStartCbk) { if (defData->nonDefaultWarnings++ < defData->settings->NonDefaultWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The NONDEFAULTRULE statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g.", defData->VersionNum); defData->defError(6545, defData->defMsg); free(defData->defMsg); @@ -5117,7 +5064,7 @@ nondefault_prop: T_STRING NUMBER char* str = defData->ringCopy(" "); propTp = defData->session->NDefProp.propType($1); CHKPROPTYPE(propTp, $1, "NONDEFAULTRULE"); - sprintf(str, "%g", $2); + snprintf(str, 24, "%g", $2); defData->NonDefault.addNumProperty($1, $2, str, propTp); } } @@ -5148,8 +5095,7 @@ styles_start: K_STYLES NUMBER ';' if (defData->VersionNum < 5.6) { if (defData->callbacks->StylesStartCbk) { if (defData->stylesWarnings++ < defData->settings->StylesWarnings) { - defData->defMsg = (char*)malloc(1000); - sprintf (defData->defMsg, + asprintf (&defData->defMsg, "The STYLES statement is available in version 5.6 and later.\nHowever, your DEF file is defined with version %g", defData->VersionNum); defData->defError(6546, defData->defMsg); free(defData->defMsg); diff --git a/lefdef/src/def/def/def_keywords.cpp b/lefdef/src/def/def/def_keywords.cpp index 89935f90..7fb48557 100644 --- a/lefdef/src/def/def/def_keywords.cpp +++ b/lefdef/src/def/def/def_keywords.cpp @@ -253,9 +253,9 @@ defrData::lines2str(long long lines) { #ifdef _WIN32 - sprintf(lineBuffer, "%I64d", lines); + snprintf(lineBuffer, sizeof(lineBuffer), "%I64d", lines); #else - sprintf(lineBuffer, "%lld", lines); + snprintf(lineBuffer, sizeof(lineBuffer), "%lld", lines); #endif return lineBuffer; @@ -579,8 +579,7 @@ defrData::sublex(YYSTYPE *pYylval) } if (defInvalidChar) { - outMsg = (char*)malloc(500 + strlen(deftoken)); - sprintf(outMsg, "Invalid characters found in \'%s\'.\nThese characters might be using the character types other than English.\nCreate characters by specifying valid characters types.", + asprintf(&outMsg, "Invalid characters found in \'%s\'.\nThese characters might be using the character types other than English.\nCreate characters by specifying valid characters types.", deftoken); defError(6008, outMsg); free(outMsg); @@ -630,9 +629,8 @@ defrData::sublex(YYSTYPE *pYylval) if ((numVal >= lVal) && (numVal <= rVal)) return NUMBER; /* YES, it's really a number */ else { - char* str = (char*)malloc(strlen(deftoken) - +strlen(session->FileName)+350); - sprintf(str, + char *str; + asprintf(&str, " in %s at line %s\n", session->FileName, lines2str(nlines)); fflush(stdout); @@ -655,9 +653,8 @@ defrData::sublex(YYSTYPE *pYylval) if ((numVal >= lVal) && (numVal <= rVal)) return NUMBER; /* YES, it's really a number */ else { - char* str = (char*)malloc(strlen(deftoken) - +strlen(session->FileName)+350); - sprintf(str, + char *str; + asprintf(&str, " in %s at line %s\n", session->FileName, lines2str(nlines)); fflush(stdout); @@ -956,35 +953,28 @@ defrData::defError(int msgNum, const char *s) { /* PCR 690679, probably missing space before a ';' */ if (strcmp(s, "parse error") == 0) { if ((len > 1) && (deftoken[len] == ';')) { - str = (char*)malloc(len + strlen(s) + strlen(session->FileName) + 350); - sprintf(str, "ERROR (DEFPARS-%d): %s, file %s at line %s\nLast token was <%s>, space is missing before <;>\n", + asprintf(&str, "ERROR (DEFPARS-%d): %s, file %s at line %s\nLast token was <%s>, space is missing before <;>\n", msgNum, s, session->FileName, lines2str(nlines), curToken); } else if ((pvLen > 1) && (pv_deftoken[pvLen] == ';')) { - str = (char*)malloc(pvLen + strlen(s) + strlen(session->FileName) + 350); - sprintf(str, "ERROR (DEFPARS-%d): %s, file %s at line %s\nLast token was <%s>, space is missing before <;>\n", + asprintf(&str, "ERROR (DEFPARS-%d): %s, file %s at line %s\nLast token was <%s>, space is missing before <;>\n", msgNum, s, session->FileName, lines2str(nlines-1), pvToken); } else { - str = (char*)malloc(len + strlen(session->FileName) + 350); - sprintf(str, "ERROR (DEFPARS-%d): Def parser has encountered an error in file %s at line %s, on token %s.\nProblem can be syntax error on the def file or an invalid parameter name.\nDouble check the syntax on the def file with the LEFDEF Reference Manual.\n", + asprintf(&str, "ERROR (DEFPARS-%d): Def parser has encountered an error in file %s at line %s, on token %s.\nProblem can be syntax error on the def file or an invalid parameter name.\nDouble check the syntax on the def file with the LEFDEF Reference Manual.\n", msgNum, session->FileName, lines2str(nlines), curToken); } } else if (strcmp(s, "syntax error") == 0) { if ((len > 1) && (deftoken[len] == ';')) { - str = (char*)malloc(len + strlen(s) + strlen(session->FileName) + 350); - sprintf(str, "ERROR (DEFPARS-%d): %s, file %s at line %s\nLast token was <%s>, space is missing before <;>\n", + asprintf(&str, "ERROR (DEFPARS-%d): %s, file %s at line %s\nLast token was <%s>, space is missing before <;>\n", msgNum, s, session->FileName, lines2str(nlines), curToken); } else if ((pvLen > 1) && (pv_deftoken[pvLen] == ';')) { - str = (char*)malloc(pvLen + strlen(s) + strlen(session->FileName) + 350); - sprintf(str, "ERROR (DEFPARS-%d): %s, file %s at line %s\nLast token was <%s>, space is missing before <;>\n", + asprintf(&str, "ERROR (DEFPARS-%d): %s, file %s at line %s\nLast token was <%s>, space is missing before <;>\n", msgNum, s, session->FileName, lines2str(nlines-1), pvToken); } else { - str = (char*)malloc(len + strlen(session->FileName) + 350); - sprintf(str, "ERROR (DEFPARS-%d): Def parser has encountered an error in file %s at line %s, on token %s.\nProblem can be syntax error on the def file or an invalid parameter name.\nDouble check the syntax on the def file with the LEFDEF Reference Manual.\n", + asprintf(&str, "ERROR (DEFPARS-%d): Def parser has encountered an error in file %s at line %s, on token %s.\nProblem can be syntax error on the def file or an invalid parameter name.\nDouble check the syntax on the def file with the LEFDEF Reference Manual.\n", msgNum, session->FileName, lines2str(nlines), curToken); } } else { - str = (char*)malloc(len + strlen(s) + strlen(session->FileName) + 350); - sprintf(str, "ERROR (DEFPARS-%d): %s Error in file %s at line %s, on token %s.\nUpdate the def file before parsing the file again.\n", + asprintf(&str, "ERROR (DEFPARS-%d): %s Error in file %s at line %s, on token %s.\nUpdate the def file before parsing the file again.\n", msgNum, s, session->FileName, lines2str(nlines), curToken); } @@ -1005,6 +995,7 @@ defrData::defyyerror(const char *s) { void defrData::defInfo(int msgNum, const char *s) { int i; + char *str; for (i = 0; i < settings->nDDMsgs; i++) { /* check if info has been disable */ if (settings->disableDMsgs[i] == msgNum) @@ -1012,16 +1003,12 @@ defrData::defInfo(int msgNum, const char *s) { } if (settings->ContextWarningLogFunction) { - char* str = (char*)malloc(strlen(deftoken)+strlen(s) - +strlen(session->FileName)+350); - sprintf(str, "INFO (DEFPARS-%d): %s See file %s at line %s.\n", + asprintf(&str, "INFO (DEFPARS-%d): %s See file %s at line %s.\n", msgNum, s, session->FileName, lines2str(nlines)); (*settings->ContextWarningLogFunction)(session->UserData, str); free(str); } else if (settings->WarningLogFunction) { - char* str = (char*)malloc(strlen(deftoken)+strlen(s) - +strlen(session->FileName)+350); - sprintf(str, "INFO (DEFPARS-%d): %s See file %s at line %s.\n", + asprintf(&str, "INFO (DEFPARS-%d): %s See file %s at line %s.\n", msgNum, s, session->FileName, lines2str(nlines)); (*settings->WarningLogFunction)(str); free(str); @@ -1060,6 +1047,7 @@ defrData::defInfo(int msgNum, const char *s) { void defrData::defWarning(int msgNum, const char *s) { int i; + char *str; for (i = 0; i nDDMsgs; i++) { /* check if warning has been disable */ if (settings->disableDMsgs[i] == msgNum) @@ -1067,16 +1055,12 @@ defrData::defWarning(int msgNum, const char *s) { } if (settings->ContextWarningLogFunction) { - char* str = (char*)malloc(strlen(deftoken)+strlen(s) - +strlen(session->FileName)+350); - sprintf(str, "WARNING (DEFPARS-%d): %s See file %s at line %s.\n", + asprintf(&str, "WARNING (DEFPARS-%d): %s See file %s at line %s.\n", msgNum, s, session->FileName, lines2str(nlines)); (*settings->ContextWarningLogFunction)(session->UserData, str); free(str); } else if (settings->WarningLogFunction) { - char* str = (char*)malloc(strlen(deftoken)+strlen(s) - +strlen(session->FileName)+350); - sprintf(str, "WARNING (DEFPARS-%d): %s See file %s at line %s.\n", + asprintf(&str, "WARNING (DEFPARS-%d): %s See file %s at line %s.\n", msgNum, s, session->FileName, lines2str(nlines)); (*settings->WarningLogFunction)(str); free(str); diff --git a/lefdef/src/def/def/defiNonDefault.cpp b/lefdef/src/def/def/defiNonDefault.cpp index e6738e08..49b46eee 100644 --- a/lefdef/src/def/def/defiNonDefault.cpp +++ b/lefdef/src/def/def/defiNonDefault.cpp @@ -319,11 +319,12 @@ int defiNonDefault::numLayers() const { } const char* defiNonDefault::layerName(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numLayers_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return layerName_[index]; @@ -331,33 +332,36 @@ const char* defiNonDefault::layerName(int index) const { // Will be obsoleted in 5.7 double defiNonDefault::layerWidth(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numLayers_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return width_[index]; } int defiNonDefault::layerWidthVal(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numLayers_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return (int)width_[index]; } int defiNonDefault::hasLayerDiagWidth(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numLayers_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return hasDiagWidth_[index]; @@ -365,44 +369,48 @@ int defiNonDefault::hasLayerDiagWidth(int index) const { // Will be obsoleted in 5.7 double defiNonDefault::layerDiagWidth(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numLayers_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return diagWidth_[index]; } int defiNonDefault::layerDiagWidthVal(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numLayers_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return (int)diagWidth_[index]; } int defiNonDefault::hasLayerWireExt(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numLayers_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return hasWireExt_[index]; } int defiNonDefault::hasLayerSpacing(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numLayers_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return hasSpacing_[index]; @@ -410,22 +418,24 @@ int defiNonDefault::hasLayerSpacing(int index) const { // Will be obsoleted in 5.7 double defiNonDefault::layerWireExt(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numLayers_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return wireExt_[index]; } int defiNonDefault::layerWireExtVal(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numLayers_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return (int)wireExt_[index]; @@ -433,22 +443,24 @@ int defiNonDefault::layerWireExtVal(int index) const { // Will be obsoleted in 5.7 double defiNonDefault::layerSpacing(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numLayers_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return spacing_[index]; } int defiNonDefault::layerSpacingVal(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numLayers_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return (int)spacing_[index]; @@ -459,11 +471,12 @@ int defiNonDefault::numVias() const { } const char* defiNonDefault::viaName(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numVias_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return viaNames_[index]; @@ -474,11 +487,12 @@ int defiNonDefault::numViaRules() const { } const char* defiNonDefault::viaRuleName(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numViaRules_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return viaRuleNames_[index]; @@ -489,22 +503,24 @@ int defiNonDefault::numMinCuts() const { } const char* defiNonDefault::cutLayerName(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numMinCuts_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return cutLayerName_[index]; } int defiNonDefault::numCuts(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numMinCuts_) { - sprintf (msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6090): The index number %d specified for the NONDEFAULT LAYER is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numLayers_); defiError(0, 6090, msg, defData); + free(msg); return 0; } return numCuts_[index]; @@ -639,66 +655,72 @@ void defiNonDefault::addNumProperty(const char* name, const double d, } const char* defiNonDefault::propName(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6091): The index number %d specified for the NONDEFAULT PROPERTY is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6091): The index number %d specified for the NONDEFAULT PROPERTY is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6091, msg, defData); + free(msg); return 0; } return names_[index]; } const char* defiNonDefault::propValue(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6091): The index number %d specified for the NONDEFAULT PROPERTY is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6091): The index number %d specified for the NONDEFAULT PROPERTY is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6091, msg, defData); + free(msg); return 0; } return values_[index]; } double defiNonDefault::propNumber(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6091): The index number %d specified for the NONDEFAULT PROPERTY is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6091): The index number %d specified for the NONDEFAULT PROPERTY is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6091, msg, defData); + free(msg); return 0; } return dvalues_[index]; } const char defiNonDefault::propType(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6091): The index number %d specified for the NONDEFAULT PROPERTY is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6091): The index number %d specified for the NONDEFAULT PROPERTY is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6091, msg, defData); + free(msg); return 0; } return types_[index]; } int defiNonDefault::propIsNumber(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6091): The index number %d specified for the NONDEFAULT PROPERTY is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6091): The index number %d specified for the NONDEFAULT PROPERTY is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6091, msg, defData); + free(msg); return 0; } return dvalues_[index] ? 1 : 0; } int defiNonDefault::propIsString(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6091): The index number %d specified for the NONDEFAULT PROPERTY is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6091): The index number %d specified for the NONDEFAULT PROPERTY is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6091, msg, defData); + free(msg); return 0; } return dvalues_[index] ? 0 : 1; diff --git a/lefdef/src/def/def/defiPinProp.cpp b/lefdef/src/def/def/defiPinProp.cpp index 63b5fa0e..8cd38c21 100644 --- a/lefdef/src/def/def/defiPinProp.cpp +++ b/lefdef/src/def/def/defiPinProp.cpp @@ -226,11 +226,12 @@ int defiPinProp::numProps() const { const char* defiPinProp::propName(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6120): The index number %d specified for the PIN PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6120): The index number %d specified for the PIN PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6120, msg, defData); + free(msg); return 0; } return propNames_[index]; @@ -238,11 +239,12 @@ const char* defiPinProp::propName(int index) const { const char* defiPinProp::propValue(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6120): The index number %d specified for the PIN PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6120): The index number %d specified for the PIN PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6120, msg, defData); + free(msg); return 0; } return propValues_[index]; @@ -250,11 +252,12 @@ const char* defiPinProp::propValue(int index) const { double defiPinProp::propNumber(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6120): The index number %d specified for the PIN PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6120): The index number %d specified for the PIN PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6120, msg, defData); + free(msg); return 0; } return propDValues_[index]; @@ -262,11 +265,12 @@ double defiPinProp::propNumber(int index) const { const char defiPinProp::propType(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6120): The index number %d specified for the PIN PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6120): The index number %d specified for the PIN PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6120, msg, defData); + free(msg); return 0; } return propTypes_[index]; @@ -274,11 +278,12 @@ const char defiPinProp::propType(int index) const { int defiPinProp::propIsNumber(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6120): The index number %d specified for the PIN PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6120): The index number %d specified for the PIN PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6120, msg, defData); + free(msg); return 0; } return propDValues_[index] ? 1 : 0; @@ -286,11 +291,12 @@ int defiPinProp::propIsNumber(int index) const { int defiPinProp::propIsString(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6120): The index number %d specified for the PIN PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6120): The index number %d specified for the PIN PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6120, msg, defData); + free(msg); return 0; } return propDValues_[index] ? 0 : 1; diff --git a/lefdef/src/def/def/defiRegion.cpp b/lefdef/src/def/def/defiRegion.cpp index 0fdda45f..914f8388 100644 --- a/lefdef/src/def/def/defiRegion.cpp +++ b/lefdef/src/def/def/defiRegion.cpp @@ -270,11 +270,12 @@ int defiRegion::numProps() const { const char* defiRegion::propName(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6130): The index number %d specified for the REGION PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6130): The index number %d specified for the REGION PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6130, msg, defData); + free(msg); return 0; } return propNames_[index]; @@ -282,11 +283,12 @@ const char* defiRegion::propName(int index) const { const char* defiRegion::propValue(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6130): The index number %d specified for the REGION PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6130): The index number %d specified for the REGION PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6130, msg, defData); + free(msg); return 0; } return propValues_[index]; @@ -294,11 +296,12 @@ const char* defiRegion::propValue(int index) const { double defiRegion::propNumber(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6130): The index number %d specified for the REGION PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6130): The index number %d specified for the REGION PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6130, msg, defData); + free(msg); return 0; } return propDValues_[index]; @@ -306,33 +309,36 @@ double defiRegion::propNumber(int index) const { const char defiRegion::propType(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6130): The index number %d specified for the REGION PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6130): The index number %d specified for the REGION PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6130, msg, defData); + free(msg); return 0; } return propTypes_[index]; } int defiRegion::propIsNumber(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6130): The index number %d specified for the REGION PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6130): The index number %d specified for the REGION PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6130, msg, defData); + free(msg); return 0; } return propDValues_[index] ? 1 : 0; } int defiRegion::propIsString(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6130): The index number %d specified for the REGION PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6130): The index number %d specified for the REGION PROPERTY is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6130, msg, defData); + free(msg); return 0; } return propDValues_[index] ? 0 : 1; @@ -344,11 +350,12 @@ const char* defiRegion::name() const { int defiRegion::xl(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numRectangles_) { - sprintf (msg, "ERROR (DEFPARS-6131): The index number %d specified for the REGION RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6131): The index number %d specified for the REGION RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numRectangles_); defiError(0, 6131, msg, defData); + free(msg); return 0; } return xl_[index]; @@ -356,11 +363,12 @@ int defiRegion::xl(int index) const { int defiRegion::yl(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numRectangles_) { - sprintf (msg, "ERROR (DEFPARS-6131): The index number %d specified for the REGION RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6131): The index number %d specified for the REGION RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numRectangles_); defiError(0, 6131, msg, defData); + free(msg); return 0; } return yl_[index]; @@ -368,11 +376,12 @@ int defiRegion::yl(int index) const { int defiRegion::xh(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numRectangles_) { - sprintf (msg, "ERROR (DEFPARS-6131): The index number %d specified for the REGION RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6131): The index number %d specified for the REGION RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numRectangles_); defiError(0, 6131, msg, defData); + free(msg); return 0; } return xh_[index]; @@ -380,11 +389,12 @@ int defiRegion::xh(int index) const { int defiRegion::yh(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numRectangles_) { - sprintf (msg, "ERROR (DEFPARS-6131): The index number %d specified for the REGION RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6131): The index number %d specified for the REGION RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numRectangles_); defiError(0, 6131, msg, defData); + free(msg); return 0; } return yh_[index]; diff --git a/lefdef/src/def/def/defiRowTrack.cpp b/lefdef/src/def/def/defiRowTrack.cpp index 85ee0314..33d7356f 100644 --- a/lefdef/src/def/def/defiRowTrack.cpp +++ b/lefdef/src/def/def/defiRowTrack.cpp @@ -240,11 +240,12 @@ int defiRow::numProps() const { const char* defiRow::propName(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6140): The index number %d specified for the VIA LAYER RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6140): The index number %d specified for the VIA LAYER RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6140, msg, defData); + free(msg); return 0; } return propNames_[index]; @@ -252,55 +253,60 @@ const char* defiRow::propName(int index) const { const char* defiRow::propValue(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6140): The index number %d specified for the VIA LAYER RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6140): The index number %d specified for the VIA LAYER RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6140, msg, defData); + free(msg); return 0; } return propValues_[index]; } double defiRow::propNumber(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6140): The index number %d specified for the VIA LAYER RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6140): The index number %d specified for the VIA LAYER RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6140, msg, defData); + free(msg); return 0; } return propDValues_[index]; } const char defiRow::propType(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6140): The index number %d specified for the VIA LAYER RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6140): The index number %d specified for the VIA LAYER RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6140, msg, defData); + free(msg); return 0; } return propTypes_[index]; } int defiRow::propIsNumber(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6140): The index number %d specified for the VIA LAYER RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6140): The index number %d specified for the VIA LAYER RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6140, msg, defData); + free(msg); return 0; } return propDValues_[index] ? 1 : 0; } int defiRow::propIsString(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numProps_) { - sprintf (msg, "ERROR (DEFPARS-6140): The index number %d specified for the VIA LAYER RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6140): The index number %d specified for the VIA LAYER RECTANGLE is invalide.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numProps_); defiError(0, 6140, msg, defData); + free(msg); return 0; } return propDValues_[index] ? 0 : 1; diff --git a/lefdef/src/def/def/defiSlot.cpp b/lefdef/src/def/def/defiSlot.cpp index c9ec6354..8c284fbd 100644 --- a/lefdef/src/def/def/defiSlot.cpp +++ b/lefdef/src/def/def/defiSlot.cpp @@ -194,11 +194,12 @@ int defiSlot::numRectangles() const { int defiSlot::xl(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numRectangles_) { - sprintf (msg, "ERROR (DEFPARS-6160): The index number %d specified for the SLOT RECTANGLE is invalid.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6160): The index number %d specified for the SLOT RECTANGLE is invalid.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numRectangles_); defiError(0, 6160, msg, defData); + free(msg); return 0; } return xl_[index]; @@ -206,11 +207,12 @@ int defiSlot::xl(int index) const { int defiSlot::yl(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numRectangles_) { - sprintf (msg, "ERROR (DEFPARS-6160): The index number %d specified for the SLOT RECTANGLE is invalid.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6160): The index number %d specified for the SLOT RECTANGLE is invalid.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numRectangles_); defiError(0, 6160, msg, defData); + free(msg); return 0; } return yl_[index]; @@ -218,11 +220,12 @@ int defiSlot::yl(int index) const { int defiSlot::xh(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numRectangles_) { - sprintf (msg, "ERROR (DEFPARS-6160): The index number %d specified for the SLOT RECTANGLE is invalid.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6160): The index number %d specified for the SLOT RECTANGLE is invalid.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numRectangles_); defiError(0, 6160, msg, defData); + free(msg); return 0; } return xh_[index]; @@ -230,11 +233,12 @@ int defiSlot::xh(int index) const { int defiSlot::yh(int index) const { - char msg[160]; + char *msg; if (index < 0 || index >= numRectangles_) { - sprintf (msg, "ERROR (DEFPARS-6160): The index number %d specified for the SLOT RECTANGLE is invalid.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", + asprintf (&msg, "ERROR (DEFPARS-6160): The index number %d specified for the SLOT RECTANGLE is invalid.\nValid index number is from 0 to %d. Specify a valid index number and then try again.", index, numRectangles_); defiError(0, 6160, msg, defData); + free(msg); return 0; } return yh_[index]; diff --git a/lefdef/src/def/defzlib/CMakeLists.txt b/lefdef/src/def/defzlib/CMakeLists.txt index bf160445..e1f96319 100644 --- a/lefdef/src/def/defzlib/CMakeLists.txt +++ b/lefdef/src/def/defzlib/CMakeLists.txt @@ -11,7 +11,7 @@ ) add_library ( defzlib ${cpps} ) -# target_link_libraries ( defzlib def z ) + target_link_libraries ( defzlib def z ) set_target_properties ( defzlib PROPERTIES VERSION 5.8 SOVERSION 5 ) install ( TARGETS defzlib DESTINATION lib${LIB_SUFFIX} ) diff --git a/lefdef/src/lef/lef/lef_keywords.cpp b/lefdef/src/lef/lef/lef_keywords.cpp index c7cfed65..0134c885 100644 --- a/lefdef/src/lef/lef/lef_keywords.cpp +++ b/lefdef/src/lef/lef/lef_keywords.cpp @@ -280,7 +280,7 @@ qStrCopy(char *string) char *retStr; retStr = (char*) lefMalloc(len); - sprintf(retStr, "\"%s\"", string); + snprintf(retStr, len, "\"%s\"", string); return retStr; } @@ -745,8 +745,9 @@ lefsublex() } if (lefData->lefInvalidChar) { - outStr = (char*) lefMalloc(500 + strlen(lefData->current_token)); - sprintf(outStr, "Invalid characters found in \'%s\'.\nThese characters might have created by character types other than English.", + int len = 500 + strlen(lefData->current_token); + outStr = (char*) lefMalloc(len); + snprintf(outStr, len, "Invalid characters found in \'%s\'.\nThese characters might have created by character types other than English.", lefData->current_token); lefError(1008, outStr); lefFree(outStr); @@ -1025,47 +1026,56 @@ lefError(int msgNum, // PCR 690679, probably missing space before a ';' if (strcmp(s, "parse error") == 0) { if ((len > 1) && (lefData->current_token[len] == ';')) { - str = (char*) lefMalloc(len + strlen(s) + strlen(lefData->lefrFileName) + 350); - sprintf(str, "ERROR (LEFPARS-%d): %s, see file %s at line %d\nLast token was <%s>, space is missing before <;>\n", + int buflen = len + strlen(s) + strlen(lefData->lefrFileName) + 350; + str = (char*) lefMalloc(buflen); + snprintf(str, buflen, "ERROR (LEFPARS-%d): %s, see file %s at line %d\nLast token was <%s>, space is missing before <;>\n", msgNum, s, lefData->lefrFileName, lefData->lef_nlines, curToken); } else if ((pvLen > 1) && (lefData->pv_token[pvLen] == ';')) { - str = (char*) lefMalloc(pvLen + strlen(s) + strlen(lefData->lefrFileName) + 350); - sprintf(str, "ERROR (LEFPARS-%d): %s, see file %s at line %d\nLast token was <%s>, space is missing before <;>\n", + int buflen = pvLen + strlen(s) + strlen(lefData->lefrFileName) + 350; + str = (char*) lefMalloc(buflen); + snprintf(str, buflen, "ERROR (LEFPARS-%d): %s, see file %s at line %d\nLast token was <%s>, space is missing before <;>\n", msgNum, s, lefData->lefrFileName, lefData->lef_nlines - 1, pvToken); } else if ((lefData->current_token[0] == '"') && (lefData->spaceMissing)) { // most likely space is missing after the end " - str = (char*) lefMalloc(len + strlen(s) + strlen(lefData->lefrFileName) + 350); - sprintf(str, "ERROR (LEFPARS-%d): %s, see file %s at line %d\nLast token was <%s\">, space is missing between the closing \" of the string and ;.\n", + int buflen = len + strlen(s) + strlen(lefData->lefrFileName) + 350; + str = (char*) lefMalloc(buflen); + snprintf(str, buflen, "ERROR (LEFPARS-%d): %s, see file %s at line %d\nLast token was <%s\">, space is missing between the closing \" of the string and ;.\n", 1010, s, lefData->lefrFileName, lefData->lef_nlines, curToken); lefData->spaceMissing = 0; } else { - str = (char*) lefMalloc(len + strlen(lefData->lefrFileName) + 350); - sprintf(str, "ERROR (LEFPARS-%d): Lef parser has encountered an error in file %s at line %d, on token %s.\nProblem can be syntax error on the lef file or an invalid parameter name.\nDouble check the syntax on the lef file with the LEFDEF Reference Manual.\n", + int buflen = len + strlen(s) + strlen(lefData->lefrFileName) + 350; + str = (char*) lefMalloc(buflen); + snprintf(str, buflen, "ERROR (LEFPARS-%d): Lef parser has encountered an error in file %s at line %d, on token %s.\nProblem can be syntax error on the lef file or an invalid parameter name.\nDouble check the syntax on the lef file with the LEFDEF Reference Manual.\n", msgNum, lefData->lefrFileName, lefData->lef_nlines, curToken); } } else if (strcmp(s, "syntax error") == 0) { // linux machines if ((len > 1) && (lefData->current_token[len] == ';')) { - str = (char*) lefMalloc(len + strlen(s) + strlen(lefData->lefrFileName) + 350); - sprintf(str, "ERROR (LEFPARS-%d): %s, see file %s at line %d\nLast token was <%s>, space is missing before <;>\n", + int buflen = len + strlen(s) + strlen(lefData->lefrFileName) + 350; + str = (char*) lefMalloc(buflen); + snprintf(str, buflen, "ERROR (LEFPARS-%d): %s, see file %s at line %d\nLast token was <%s>, space is missing before <;>\n", msgNum, s, lefData->lefrFileName, lefData->lef_nlines, curToken); } else if ((pvLen > 1) && (lefData->pv_token[pvLen] == ';')) { - str = (char*) lefMalloc(pvLen + strlen(s) + strlen(lefData->lefrFileName) + 350); - sprintf(str, "ERROR (LEFPARS-%d): %s, see file %s at line %d\nLast token was <%s>, space is missing before <;>\n", + int buflen = pvLen + strlen(s) + strlen(lefData->lefrFileName) + 350; + str = (char*) lefMalloc(buflen); + snprintf(str, buflen, "ERROR (LEFPARS-%d): %s, see file %s at line %d\nLast token was <%s>, space is missing before <;>\n", msgNum, s, lefData->lefrFileName, lefData->lef_nlines - 1, pvToken); } else if ((lefData->current_token[0] == '"') && (lefData->spaceMissing)) { // most likely space is missing after the end " - str = (char*) lefMalloc(len + strlen(s) + strlen(lefData->lefrFileName) + 350); - sprintf(str, "ERROR (LEFPARS-%d): %s, see file %s at line %d\nLast token was <%s\">, space is missing between the closing \" of the string and ;.\n", + int buflen = len + strlen(s) + strlen(lefData->lefrFileName) + 350; + str = (char*) lefMalloc(buflen); + snprintf(str, buflen, "ERROR (LEFPARS-%d): %s, see file %s at line %d\nLast token was <%s\">, space is missing between the closing \" of the string and ;.\n", 1011, s, lefData->lefrFileName, lefData->lef_nlines, curToken); lefData->spaceMissing = 0; } else { - str = (char*) lefMalloc(len + strlen(lefData->lefrFileName) + 350); - sprintf(str, "ERROR (LEFPARS-%d): Lef parser has encountered an error in file %s at line %d, on token %s.\nProblem can be syntax error on the lef file or an invalid parameter name.\nDouble check the syntax on the lef file with the LEFDEF Reference Manual.\n", + int buflen = len + strlen(s) + strlen(lefData->lefrFileName) + 350; + str = (char*) lefMalloc(buflen); + snprintf(str, buflen, "ERROR (LEFPARS-%d): Lef parser has encountered an error in file %s at line %d, on token %s.\nProblem can be syntax error on the lef file or an invalid parameter name.\nDouble check the syntax on the lef file with the LEFDEF Reference Manual.\n", msgNum, lefData->lefrFileName, lefData->lef_nlines, curToken); } } else { - str = (char*) lefMalloc(len + strlen(s) + strlen(lefData->lefrFileName) + 350); - sprintf(str, "ERROR (LEFPARS-%d): %s Error in file %s at line %d, on token %s.\n", + int buflen = len + strlen(s) + strlen(lefData->lefrFileName) + 350; + str = (char*) lefMalloc(buflen); + snprintf(str, buflen, "ERROR (LEFPARS-%d): %s Error in file %s at line %d, on token %s.\n", msgNum, s, lefData->lefrFileName, lefData->lef_nlines, curToken); } fflush(stdout); @@ -1096,7 +1106,7 @@ lefInfo(int msgNum, if (disableStatus == 1) { char msgStr[60]; - sprintf(msgStr, "Message (LEFPARS-%d) has been suppressed from output.", msgNum); + snprintf(msgStr, 60, "Message (LEFPARS-%d) has been suppressed from output.", msgNum); lefWarning(2502, msgStr); return; } else if (disableStatus == 2) { @@ -1111,7 +1121,7 @@ lefInfo(int msgNum, if (lefData->msgLimit[1][msgNum]) // already printed out warning return; lefData->msgLimit[1][msgNum] = 1; - sprintf(msgStr, + snprintf(msgStr, 100, "Message (LEFPARS-%d) has exceeded the message display limit of %d", msgNum, lefSettings->MsgLimit[msgNum]); lefWarning(2503, msgStr); @@ -1122,9 +1132,9 @@ lefInfo(int msgNum, lefData->lefInfoMsgPrinted++; if (lefSettings->WarningLogFunction) { - char *str = (char*) lefMalloc(strlen(lefData->current_token) + strlen(s) + strlen(lefData->lefrFileName) - + 350); - sprintf(str, "INFO (LEFPARS-%d): %s See file %s at line %d.\n", + int buflen = strlen(lefData->current_token) + strlen(s) + strlen(lefData->lefrFileName) + 350; + char *str = (char*) lefMalloc(buflen); + snprintf(str, buflen, "INFO (LEFPARS-%d): %s See file %s at line %d.\n", msgNum, s, lefData->lefrFileName, lefData->lef_nlines); (*lefSettings->WarningLogFunction)(str); free(str); @@ -1171,7 +1181,7 @@ lefWarning(int msgNum, if (disableStatus == 1) { char msgStr[60]; - sprintf(msgStr, "Message (LEFPARS-%d) has been suppressed from output.", msgNum); + snprintf(msgStr, 60, "Message (LEFPARS-%d) has been suppressed from output.", msgNum); lefWarning(2502, msgStr); return; } else if (disableStatus == 2) { @@ -1187,7 +1197,7 @@ lefWarning(int msgNum, if (lefData->msgLimit[1][msgNum]) // already printed out warning return; lefData->msgLimit[1][msgNum] = 1; - sprintf(msgStr, + snprintf(msgStr, 100, "Message (LEFPARS-%d) has exceeded the message display limit of %d", msgNum, lefSettings->MsgLimit[msgNum]); lefWarning(2503, msgStr); @@ -1198,9 +1208,9 @@ lefWarning(int msgNum, lefData->lefWarnMsgPrinted++; if (lefSettings->WarningLogFunction) { - char *str = (char*) lefMalloc(strlen(lefData->current_token) + strlen(s) + strlen(lefData->lefrFileName) - + 350); - sprintf(str, "WARNING (LEFPARS-%d): %s See file %s at line %d.\n", + int buflen = strlen(lefData->current_token) + strlen(s) + strlen(lefData->lefrFileName) + 350; + char *str = (char*) lefMalloc(buflen); + snprintf(str, buflen, "WARNING (LEFPARS-%d): %s See file %s at line %d.\n", msgNum, s, lefData->lefrFileName, lefData->lef_nlines); (*lefSettings->WarningLogFunction)(str); free(str); diff --git a/lefdef/src/lef/lefzlib/CMakeLists.txt b/lefdef/src/lef/lefzlib/CMakeLists.txt index 99b8e34d..9fda26fa 100644 --- a/lefdef/src/lef/lefzlib/CMakeLists.txt +++ b/lefdef/src/lef/lefzlib/CMakeLists.txt @@ -11,7 +11,7 @@ ) add_library ( lefzlib ${cpps} ) -# target_link_libraries ( lefzlib lef z ) + target_link_libraries ( lefzlib lef z ) set_target_properties ( lefzlib PROPERTIES VERSION 5.8 SOVERSION 5 ) install ( TARGETS lefzlib DESTINATION lib${LIB_SUFFIX} )