
Thanks Wouter,
I have committed the patch (revision 1833).
/js
On Sun, Feb 07, 2016 at 06:02:45PM +0100, Wouter van Kesteren wrote:
From man sprintf:
NOTES Some programs imprudently rely on code such as the following
sprintf(buf, "%s some further text", buf); to append text to buf. However, the standards explicitly note that the results are undefined if source and destination buffers overlap when calling sprintf(), snprintf(), vsprintf(), and vsnprintf(). Depending on the version of gcc(1) used, and the compiler options employed, calls such as the above will not produce the expected results.
On my system with gcc-5.3, glibc-2.22 this makes the tests on 0.4.8 fail. With this patch the tests pass. This patch is also applicable to 0.5.0, however the testsuite of 0.5.0 fails with:
116,118c122,123 < ../../mibs/ietf/IF-MIB:1741 warning: legal status change from `current' to `deprecated' for `ifCompliance' < ../../mibs/ietf/IF-MIB:1741 warning: description of MODULE-COMPLIANCE `ifCompliance' changed
< ./IF-MIB.old:1244 info: previous definition of `ifCompliance'
./IF-MIB.old:1244 compliance `ifCompliance' has been deleted ../../mibs/ietf/IF-MIB:1741 warning: compliance `ifCompliance' has been added
So consider this email both a patch, and a bugreport.
tools/smidiff.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/tools/smidiff.c b/tools/smidiff.c index dcd2166..c94a143 100644 --- a/tools/smidiff.c +++ b/tools/smidiff.c @@ -941,15 +941,17 @@ getStringRange(SmiType *smiType) SmiRange *range; int i; char *str, *subRange;
size_t strLen;
str = NULL; for(i = 0, range = smiGetFirstRange(smiType); range; i++, range = smiGetNextRange(range)) {
if (i) {
str = realloc( str, strlen( str ) +2 );
strLen = strlen( str );
str = realloc( str, strLen +2 ); if( str ) {
sprintf(str, "%s|", str);
sprintf(str + strLen, "|");
}
}
@@ -961,16 +963,18 @@ getStringRange(SmiType *smiType) if( !subRange ) { return NULL; }
- str = realloc( str, strlen( str ) + strlen( subRange ) + 1 );
- strLen = strlen( str );
- str = realloc( str, strLen + strlen( subRange ) + 1 ); if( !str ) { return NULL; }
- sprintf( str, "%s%s", str, subRange );
sprintf( str + strLen, "%s", subRange );
}
- str = realloc( str, strlen( str ) + 2 );
- strLen = strlen( str );
- str = realloc( str, strLen + 2 ); if( str ) {
- sprintf(str, "%s)", str);
- sprintf(str + strLen, ")"); } return str;
} @@ -1613,6 +1617,7 @@ getStringIndexList( SmiNode *smiNode ) SmiNode *indexNode; SmiElement *smiElement; char *strIdxLst;
size_t strIdxLstLen;
smiElement = smiGetFirstElement( smiNode ); indexNode = smiGetElementNode( smiElement );
@@ -1623,10 +1628,11 @@ getStringIndexList( SmiNode *smiNode ) smiElement = smiGetNextElement( smiElement ); while ( smiElement ) { indexNode = smiGetElementNode( smiElement );
- strIdxLstLen = strlen( strIdxLst ); strIdxLst = (char *)realloc( strIdxLst,
strlen( strIdxLst ) +
strIdxLstLen + strlen( indexNode->name ) + 4 );
- sprintf( strIdxLst, "%s, `%s'", strIdxLst, indexNode->name );
- sprintf( strIdxLst + strIdxLstLen, ", `%s'", indexNode->name ); smiElement = smiGetNextElement( smiElement ); } return strIdxLst;
-- 2.7.0
-- !! This message is brought to you via the `libsmi' mailing list. !! Please do not reply to this message to unsubscribe. To unsubscribe or adjust !! your settings, send a mail message to libsmi-request@ibr.cs.tu-bs.de !! or look at https://mail.ibr.cs.tu-bs.de/listinfo/libsmi.