File tree Expand file tree Collapse file tree 2 files changed +18
-9
lines changed
common/src/codingstandards/cpp
misra/test/rules/RULE-8-7-1 Expand file tree Collapse file tree 2 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -379,8 +379,16 @@ module OOB {
379379 StrncatLibraryFunction ( ) { this .getName ( ) = getNameOrInternalName ( [ "strncat" , "wcsncat" ] ) }
380380
381381 override predicate getALengthParameterIndex ( int i ) {
382- // `strncat` and `wcsncat` exclude the size of a null terminator
383- i = 2
382+ // `strncat` and `wcsncat` exclude the size of a null terminator, but
383+ // both stops copying right after the null terminator is encountered.
384+ // In fact, they don't care if the source buffer is null-terminated
385+ // or not.
386+ none ( )
387+ }
388+
389+ override predicate getANullTerminatedParameterIndex ( int i ) {
390+ // `strncat` does not require null-terminated parameters
391+ none ( )
384392 }
385393 }
386394
Original file line number Diff line number Diff line change @@ -411,14 +411,15 @@ void test_wrong_buf_size(void) {
411411
412412 // strncat
413413 {
414- char buf[64 ];
415- char buf2[64 ];
416- strncat (buf, buf2, sizeof (buf )); // COMPLIANT
417- strncat (buf, buf2, sizeof (buf ) + 1 ); // NON_COMPLIANT
418- strncat (buf, buf2, sizeof (buf ) - 1 ); // COMPLIANT
419- strncat (buf + 1 , buf2, sizeof (buf )); // NON_COMPLIANT
420- strncat (buf, buf2 + 1 , sizeof (buf ) * 2 ); // NON_COMPLIANT
414+ char buf[65 ];
415+ char buf2[32 ];
416+ strncat (buf, buf2, sizeof (buf2 )); // COMPLIANT
417+ strncat (buf, buf2, sizeof (buf2 ) + 1 ); // NON_COMPLIANT
418+ strncat (buf, buf2, sizeof (buf2 ) - 1 ); // COMPLIANT
419+ strncat (buf + 1 , buf2, sizeof (buf2 )); // COMPLIANT
420+ strncat (buf, buf2 + 1 , sizeof (buf2 ) * 2 ); // NON_COMPLIANT
421421 }
422+
422423 // wcsxfrm
423424 {
424425 wchar_t wbuf[64 ];
You can’t perform that action at this time.
0 commit comments