Skip to content

Commit 1d3fe82

Browse files
authored
Add missing STD Library Identifiers (danmar#7325)
Added a STDLIB_IDENTIFIERS for C11 as well as updated the C99 once based on, C99: https://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf C11: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf in the misra.py
1 parent a9f9949 commit 1d3fe82

File tree

2 files changed

+246
-25
lines changed

2 files changed

+246
-25
lines changed

addons/misra.py

Lines changed: 184 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,28 @@ def grouped(iterable, n):
4545
['int', 'uint', 'int_least', 'uint_least', 'int_fast', 'uint_fast'],
4646
[8, 16, 32, 64])]
4747

48+
STDINT_H_DEFINES_MIN = ['%s%d_MIN' % (n, v) for n, v in itertools.product(
49+
['INT', 'INT_LEAST', 'INT_FAST',],
50+
[8, 16, 32, 64])]
51+
52+
STDINT_H_DEFINES_MAX = ['%s%d_MAX' % (n, v) for n, v in itertools.product(
53+
['INT', 'UINT','INT_LEAST','UINT_LEAST', 'INT_FAST', 'UINT_FAST',],
54+
[8, 16, 32, 64])]
4855

56+
STDINT_H_DEFINES_C = ['%s%d_C' % (n, v) for n, v in itertools.product(
57+
['INT', 'UINT'],
58+
[8, 16, 32, 64])]
59+
60+
61+
INTTYPES_H_DEFINES = ['%s%d' % (n, v) for n, v in itertools.product(
62+
['PRId', 'PRIi', 'PRIo', 'PRIu', 'PRIx', 'PRIX', 'SCNd',
63+
'SCNi', 'SCNo', 'SCNu', 'SCNx', 'PRIdLEAST', 'PRIiLEAST',
64+
'PRIoLEAST', 'PRIuLEAST', 'PRIxLEAST', 'PRIXLEAST',
65+
'SCNdLEAST', 'SCNiLEAST', 'SCNoLEAST', 'SCNuLEAST',
66+
'SCNxLEAST', 'PRIdFAST', 'PRIiFAST', 'PRIoFAST', 'PRIuFAST',
67+
'PRIxFAST', 'PRIXFAST', 'SCNdFAST', 'SCNiFAST', 'SCNoFAST',
68+
'SCNuFAST', 'SCNxFAST', ],
69+
[8, 16, 32, 64])]
4970
typeBits = {
5071
'CHAR': None,
5172
'SHORT': None,
@@ -169,7 +190,8 @@ def rawlink(rawtoken):
169190

170191

171192
# Identifiers described in Section 7 "Library" of C99 Standard
172-
# Based on ISO/IEC 9899 WF14/N1256 Annex B -- Library summary
193+
# Based on ISO/IEC 9899:1999 (E) Annex B -- Library summary
194+
# (https://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf)
173195
C99_STDLIB_IDENTIFIERS = {
174196
# B.1 Diagnostics
175197
'assert.h': C90_STDLIB_IDENTIFIERS['assert.h'],
@@ -220,9 +242,13 @@ def rawlink(rawtoken):
220242
'float.h': C90_STDLIB_IDENTIFIERS['float.h'] + ['FLT_EVAL_METHOD'],
221243
# B.7 Format conversion of integer types
222244
'inttypes.h': [
245+
'PRIdMAX', 'PRIiMAX', 'PRIoMAX', 'PRIuMAX', 'PRIxMAX', 'PRIXMAX',
246+
'SCNdMAX', 'SCNiMAX', 'SCNoMAX', 'SCNuMAX', 'SCNxMAX', 'PRIdPTR',
247+
'PRIiPTR', 'PRIoPTR', 'PRIuPTR', 'PRIxPTR', 'PRIXPTR', 'SCNdPTR',
248+
'SCNiPTR', 'SCNoPTR', 'SCNuPTR', 'SCNxPTR',
223249
'imaxdiv_t', 'imaxabs', 'imaxdiv', 'strtoimax',
224250
'strtoumax', 'wcstoimax', 'wcstoumax',
225-
],
251+
] + INTTYPES_H_DEFINES,
226252
# B.8 Alternative spellings
227253
'iso646.h': [
228254
'and', 'and_eq', 'bitand', 'bitor', 'compl', 'not', 'not_eq',
@@ -246,11 +272,12 @@ def rawlink(rawtoken):
246272
'acoshl', 'asinh', 'asinhf', 'asinhl', 'atanh', 'atanhf', 'atanhl',
247273
'cosh', 'coshf', 'coshl', 'sinh', 'sinhf', 'sinhl', 'tanh', 'tanhf',
248274
'tanhl', 'expf', 'expl', 'exp2', 'exp2f', 'exp2l', 'expm1', 'expm1f',
249-
'expm1l', 'frexpf', 'frexpl', 'ilogb', 'ilogbf', 'ilogbl', 'float',
275+
'expm1l', 'frexpf', 'frexpl', 'ilogb', 'ilogbf', 'ilogbl', 'ldexpf',
250276
'ldexpl', 'logf', 'logl', 'log10f', 'log10l', 'log1p', 'log1pf',
251277
'log1pl', 'log2', 'log2f', 'log2l', 'logb', 'logbf', 'logbl', 'modff',
252278
'modfl', 'scalbn', 'scalbnf', 'scalbnl', 'scalbln', 'scalblnf',
253-
'scalblnl', 'hypotl', 'powf', 'powl', 'sqrtf', 'sqrtl', 'erf', 'erff',
279+
'scalblnl','cbrt', 'cbrtf','cbrtl', 'fabs', 'fabsf', 'fabsl',
280+
'hypotl', 'hypotf', 'powf', 'powl', 'sqrtf', 'sqrtl', 'erf', 'erff',
254281
'erfl', 'erfc', 'erfcf', 'erfcl', 'lgamma', 'lgammaf', 'lgammal',
255282
'tgamma', 'tgammaf', 'tgammal', 'ceilf', 'ceill', 'floorf', 'floorl',
256283
'nearbyint', 'nearbyintf', 'nearbyintl', 'rint', 'rintf', 'rintl',
@@ -261,7 +288,7 @@ def rawlink(rawtoken):
261288
'remquol', 'copysign', 'copysignf', 'copysignl', 'nan', 'nanf',
262289
'nanl', 'nextafter', 'nextafterf', 'nextafterl', 'nexttoward',
263290
'nexttowardf', 'nexttowardl', 'fdim', 'fdimf', 'fdiml', 'fmax',
264-
'fmaxf', 'fmaxl', 'fmin', 'fminf', 'fminl', 'fmal', 'isgreater',
291+
'fmaxf', 'fmaxl', 'fmin', 'fminf', 'fminl', 'fmaf','fmal', 'isgreater',
265292
'isgreaterequal', 'isless', 'islessequal', 'islessgreater',
266293
'isunordered',
267294
],
@@ -284,11 +311,11 @@ def rawlink(rawtoken):
284311
'UINTMAX_MAX', 'PTRDIFF_MIN', 'PTRDIFF_MAX', 'SIG_ATOMIC_MIN',
285312
'SIG_ATOMIC_MAX', 'SIZE_MAX', 'WCHAR_MIN', 'WCHAR_MAX', 'WINT_MIN',
286313
'WINT_MAX', 'INTN_C', 'UINTN_C', 'INTMAX_C', 'UINTMAX_C',
287-
] + STDINT_TYPES,
314+
] + STDINT_TYPES + STDINT_H_DEFINES_MIN + STDINT_H_DEFINES_MAX + STDINT_H_DEFINES_C,
288315
# B.18 Input/output
289316
'stdio.h': C90_STDLIB_IDENTIFIERS['stdio.h'] + [
290317
'mode', 'restrict', 'snprintf', 'vfscanf', 'vscanf',
291-
'vsnprintf', 'vsscanf',
318+
'vsnprintf', 'vsscanf','ftell'
292319
],
293320
# B.19 General utilities
294321
'stdlib.h': C90_STDLIB_IDENTIFIERS['stdlib.h'] + [
@@ -317,22 +344,148 @@ def rawlink(rawtoken):
317344
'vfwprintf', 'vfwscanf', 'vswprintf', 'vswscanf', 'vwprintf',
318345
'vwscanf', 'wprintf', 'wscanf', 'fgetwc', 'fgetws', 'fputwc', 'fputws',
319346
'fwide', 'getwc', 'getwchar', 'putwc', 'putwchar', 'ungetwc', 'wcstod',
320-
'wcstof', 'double', 'int', 'long', 'long', 'long', 'wcscpy', 'wcsncpy',
321-
'wmemcpy', 'wmemmove', 'wcscat', 'wcsncat', 'wcscmp', 'wcscoll',
347+
'wcstof', 'wcstold', 'wcstol', 'wcstoll', 'wcstoul', 'wcstoull', 'wcscpy',
348+
'wcsncpy', 'wmemcpy', 'wmemmove', 'wcscat', 'wcsncat', 'wcscmp', 'wcscoll',
322349
'wcsncmp', 'wcsxfrm', 'wmemcmp', 'wcschr', 'wcscspn', 'wcspbrk',
323350
'wcsrchr', 'wcsspn', 'wcsstr', 'wcstok', 'wmemchr', 'wcslen',
324351
'wmemset', 'wcsftime', 'btowc', 'wctob', 'mbsinit', 'mbrlen',
325352
'mbrtowc', 'wcrtomb', 'mbsrtowcs', 'wcsrtombs',
326353
],
354+
# B.24 Wide character classification and mapping utilities
355+
'wctype.h': ['wint_t', 'wctrans_t', 'wctype_t', 'WEOF',
356+
'iswalnum', 'iswalpha', 'iswblank', 'iswcntrl', 'iswdigit',
357+
'iswgraph', 'iswlower', 'iswprint', 'iswpunct', 'iswspace', 'iswupper',
358+
'iswxdigit', 'iswctype', 'wctype', 'towlower', 'towupper', 'towctrans',
359+
'wctrans'],
327360
}
328361

362+
# Identifiers described in Section 7 "Library" of C11 Standard
363+
# Based on ISO/IEC 9899:201x N1570 (Draft 12.04.2011) Annex B -- Library summary
364+
# (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf)
365+
C11_STDLIB_IDENTIFIERS = {
366+
# B.1 Diagnostics
367+
'assert.h': C99_STDLIB_IDENTIFIERS['assert.h']+ ['static_assert'],
368+
# B.2 Complex
369+
'complex.h': C99_STDLIB_IDENTIFIERS['complex.h']+['__STDC_NO_COMPLEX__','CMPLX','CMPLXF','CMPLXL'],
370+
# B.3 Character handling
371+
'ctype.h': C99_STDLIB_IDENTIFIERS['ctype.h'],
372+
# B.4 Errors
373+
'errno.h': C99_STDLIB_IDENTIFIERS['errno.h']+['__STDC_WANT_LIB_EXT1__', 'errno_t'],
374+
# B.5 Floating-point environment
375+
'fenv.h': C99_STDLIB_IDENTIFIERS['fenv.h'],
376+
# B.6 Characteristics of floating types
377+
'float.h': C99_STDLIB_IDENTIFIERS['float.h']+[
378+
'FLT_HAS_SUBNORM','DBL_HAS_SUBNORM','LDBL_HAS_SUBNORM',
379+
'FLT_DECIMAL_DIG','DBL_DECIMAL_DIG','LDBL_DECIMAL_DIG',
380+
'FLT_TRUE_MIN','DBL_TRUE_MIN','LDBL_TRUE_MIN'],
381+
# B.7 Format conversion of integer types
382+
'inttypes.h': C99_STDLIB_IDENTIFIERS["inttypes.h"],
383+
# B.8 Alternative spellings
384+
'iso646.h': C99_STDLIB_IDENTIFIERS["iso646.h"],
385+
# B.9 Size of integer types
386+
'limits.h': C99_STDLIB_IDENTIFIERS['limits.h'],
387+
# B.10 Localization
388+
'locale.h': C99_STDLIB_IDENTIFIERS['locale.h'],
389+
# B.11 Mathematics
390+
'math.h': C99_STDLIB_IDENTIFIERS['math.h'],
391+
# B.12 Nonlocal jumps
392+
'setjmp.h': C99_STDLIB_IDENTIFIERS['setjmp.h'],
393+
# B.13 Signal handling
394+
'signal.h': C99_STDLIB_IDENTIFIERS['signal.h'],
395+
# B.14 Alignment
396+
'stdalign.h': ['alignas','__alignas_is_defined'],
397+
# B.15 Variable arguments
398+
'stdarg.h': C99_STDLIB_IDENTIFIERS['stdarg.h'],
399+
# B.16 Atomics
400+
'stdatomic.h': ['ATOMIC_BOOL_LOCK_FREE', 'ATOMIC_CHAR_LOCK_FREE',
401+
'ATOMIC_CHAR16_T_LOCK_FREE', 'ATOMIC_CHAR32_T_LOCK_FREE', 'ATOMIC_WCHAR_T_LOCK_FREE',
402+
'ATOMIC_SHORT_LOCK_FREE', 'ATOMIC_INT_LOCK_FREE', 'ATOMIC_LONG_LOCK_FREE',
403+
'ATOMIC_LLONG_LOCK_FREE', 'ATOMIC_POINTER_LOCK_FREE', 'ATOMIC_FLAG_INIT',
404+
'memory_order', 'atomic_flag', 'memory_order_relaxed', 'memory_order_consume',
405+
'memory_order_acquire', 'memory_order_release', 'memory_order_acq_rel', 'memory_order_seq_cst',
406+
'atomic_bool', 'atomic_char', 'atomic_schar', 'atomic_uchar', 'atomic_short', 'atomic_ushort',
407+
'atomic_int', 'atomic_uint', 'atomic_long', 'atomic_ulong', 'atomic_llong', 'atomic_ullong',
408+
'atomic_char16_t', 'atomic_char32_t', 'atomic_wchar_t', 'atomic_int_least8_t',
409+
'atomic_uint_least8_t', 'atomic_int_least16_t', 'atomic_uint_least16_t',
410+
'atomic_int_least32_t', 'atomic_uint_least32_t', 'atomic_int_least64_t',
411+
'atomic_uint_least64_t', 'atomic_int_fast8_t', 'atomic_uint_fast8_t',
412+
'atomic_int_fast16_t', 'atomic_uint_fast16_t', 'atomic_int_fast32_t',
413+
'atomic_uint_fast32_t', 'atomic_int_fast64_t', 'atomic_uint_fast64_t',
414+
'atomic_intptr_t', 'atomic_uintptr_t', 'atomic_size_t', 'atomic_ptrdiff_t',
415+
'atomic_intmax_t', 'atomic_uintmax_t', 'ATOMIC_VAR_INIT', 'type kill_dependency',
416+
'atomic_thread_fence', 'atomic_signal_fence', 'atomic_is_lock_free',
417+
'atomic_store', 'atomic_store_explicit', 'atomic_load', 'atomic_load_explicit',
418+
'atomic_exchange', 'atomic_exchange_explicit', 'atomic_compare_exchange_strong',
419+
'atomic_compare_exchange_strong_explicit', 'atomic_compare_exchange_weak',
420+
'atomic_compare_exchange_weak_explicit', 'atomic_fetch_key', 'atomic_fetch_key_explicit',
421+
'atomic_flag_test_and_set', 'atomic_flag_test_and_set_explicit',
422+
'atomic_flag_clear', 'atomic_flag_clear_explicit', ],
423+
# B.17 Boolean type and values
424+
'stdbool.h': C99_STDLIB_IDENTIFIERS['stdbool.h'],
425+
# B.18 Common definitions
426+
'stddef.h': C99_STDLIB_IDENTIFIERS['stddef.h'] +
427+
['max_align_t','__STDC_WANT_LIB_EXT1__', 'rsize_t'],
428+
# B.19 Integer types
429+
'stdint.h': C99_STDLIB_IDENTIFIERS['stdint.h']+
430+
['__STDC_WANT_LIB_EXT1__', 'RSIZE_MAX'],
431+
# B.20 Input/output
432+
'stdio.h': C99_STDLIB_IDENTIFIERS['stdio.h'] +
433+
['__STDC_WANT_LIB_EXT1__', 'L_tmpnam_s', 'TMP_MAX_S', 'errno_t', 'rsize_t',
434+
'tmpfile_s', 'tmpnam_s', 'fopen_s', 'freopen_s', 'fprintf_s', 'fscanf_s',
435+
'printf_s','scanf_s','snprintf_s','sprintf_s','sscanf_s','vfprintf_s',
436+
'vfscanf_s', 'vsprintf_s', 'vsscanf_s', 'gets_s'
437+
],
438+
# B.21 General utilities
439+
'stdlib.h': C99_STDLIB_IDENTIFIERS['stdlib.h'] +
440+
['constraint_handler_t', 'set_constraint_handler_s', 'abort_handler_s',
441+
'ignore_handler_s', 'getenv_s', 'bsearch_s', 'qsort_s', 'wctomb_s',
442+
'mbstowcs_s', 'wcstombs_s'],
443+
# B.22 Noretrun
444+
'stdnoreturn.h': ['noreturn'],
445+
# B.23 String handling
446+
'string.h': C99_STDLIB_IDENTIFIERS['string.h'] +
447+
['memcpy_s', 'memmoce_s', 'strcpy_s', 'strncpy_s','strcat_s',
448+
'strtok_s', 'memset_s', 'strerror_s', 'strerrorlen_s', 'strnlen_s'],
449+
# B.24 Type-generic math
450+
'tgmath.h': C99_STDLIB_IDENTIFIERS['tgmath.h'],
451+
# B.25 Threads
452+
'threads.h': ['thread_local', 'ONCE_FLAG_INIT', 'TSS_DTOR_ITERATIONS',
453+
'cnd_t', 'thrd_t', 'tss_t', 'mtx_t', 'tss_dtor_t', 'thrd_start_t',
454+
'once_flag', 'mtx_plain', 'mtx_recursive', 'mtx_timed', 'thrd_timedout',
455+
'thrd_success', 'thrd_busy', 'thrd_error', 'thrd_nomem', 'call_once',
456+
'cnd_broadcast', 'cnd_destroy','cnd_init', 'cnd_signal', 'cnd_timedwait',
457+
'cnd_wait','mtx_destroy', 'mtx_init', 'mtx_lock', 'mtx_timedlock',
458+
'mtx_trylock', 'mtx_unlock', 'thrd_create', 'thrd_current',
459+
'thrd_detach', 'thrd_equal', 'thrd_exit', 'thrd_join', 'thrd_sleep',
460+
'thrd_yield', 'tss_create', 'tss_delete', 'tss_get', 'tss_set' ],
461+
# B.26 Date and time
462+
'time.h': C99_STDLIB_IDENTIFIERS['time.h'] + [
463+
'asctime_s', 'ctime_s', 'gmtime_s', 'localtime_s'
464+
],
465+
# B.27 Unicode utilities
466+
'uchar.h': ['mbstate_t', 'size_t', 'char16_t', 'char32_t',
467+
'mbrtoc16', 'c16rtomb', 'mbrtoc32', 'c32rtomb'
468+
],
469+
# B.28 Extended multibyte/wide character utilities
470+
'wchar.h': C99_STDLIB_IDENTIFIERS["wchar.h"]+[
471+
'fwprintf_s', 'fwscanf_s', 'snwprintf_s', 'swprintf_s', 'swscanf_s',
472+
'vfwprintf_s', 'vfwscanf_s', 'vsnwprintf_s', 'vswprintf_s', 'vswscanf_s',
473+
'vwprintf_s', 'vwscanf_s', 'wprintf_s', 'wscanf_s', 'wcscpy_s', 'wcsncpy_s',
474+
'wmemcpy_s', 'wmemmove_s', 'wcscat_s', 'wcsncat_s', 'wcstok_s', 'wcsnlen_s',
475+
'wcrtomb_s', 'mbsrtowcs_s', 'wcsrtombs_s',
476+
],
477+
# B.29 Wide character classification and mapping utilities
478+
'wctype.h': C99_STDLIB_IDENTIFIERS['wctype.h'],
479+
}
329480

330481
def isStdLibId(id_, standard='c99'):
331482
id_lists = []
332483
if standard == 'c89':
333484
id_lists = C90_STDLIB_IDENTIFIERS.values()
334-
elif standard in ('c99', 'c11'):
485+
elif standard == 'c99':
335486
id_lists = C99_STDLIB_IDENTIFIERS.values()
487+
else:
488+
id_lists = C11_STDLIB_IDENTIFIERS.values()
336489
for l in id_lists:
337490
if id_ in l:
338491
return True
@@ -349,16 +502,23 @@ def isStdLibId(id_, standard='c99'):
349502
}
350503

351504

352-
# Reserved keywords defined in ISO/IEC 9899 WF14/N1256 -- ch. 6.4.1
505+
# Reserved keywords defined in Section 6.4.1 "Language" of C99 Standard
506+
# Based on ISO/IEC 9899:1999 (E) 6.4.1 Keywords
507+
# Adding the expanding macros from Section 7 too
508+
# (https://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf)
353509
C99_ADDED_KEYWORDS = {
354510
'inline', 'restrict', '_Bool', '_Complex', '_Imaginary',
355511
'bool', 'complex', 'imaginary'
356512
}
357513

514+
# Reserved keywords defined in Section 6.4.1 "Language" of C11 Standard
515+
# Based on ISO/IEC 9899:201x N1570 (Draft 12.04.2011) 6.4.1 Keywords
516+
# Adding the expanding macros from Section 7 too
517+
# (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf)
358518
C11_ADDED_KEYWORDS = {
359519
'_Alignas', '_Alignof', '_Atomic', '_Generic', '_Noreturn',
360-
'_Statis_assert', '_Thread_local' ,
361-
'alignas', 'alignof', 'noreturn', 'static_assert'
520+
'_Static_assert', '_Thread_local' ,
521+
'alignas', 'alignof', 'noreturn', 'static_assert','thread_local'
362522
}
363523

364524
def isKeyword(keyword, standard='c99'):
@@ -1547,7 +1707,7 @@ def misra_1_4(self, cfg):
15471707
for token in cfg.tokenlist:
15481708
if token.str in ('_Atomic', '_Noreturn', '_Generic', '_Thread_local', '_Alignas', '_Alignof'):
15491709
self.reportError(token, 1, 4)
1550-
if token.str.endswith('_s') and isFunctionCall(token.next):
1710+
if token.str.endswith('_s') and isFunctionCall(token.next, cfg.standards.c):
15511711
# See C specification C11 - Annex K, page 578
15521712
if token.str in ('tmpfile_s', 'tmpnam_s', 'fopen_s', 'freopen_s', 'fprintf_s', 'fscanf_s', 'printf_s', 'scanf_s',
15531713
'snprintf_s', 'sprintf_s', 'sscanf_s', 'vfprintf_s', 'vfscanf_s', 'vprintf_s', 'vscanf_s',
@@ -1942,7 +2102,7 @@ def reportErrorIfVariableIsNotConst(variable, stringLiteral):
19422102
self.reportError(token, 7, 4)
19432103

19442104
# Check use as function parameter
1945-
if isFunctionCall(token) and token.astOperand1 and token.astOperand1.function:
2105+
if isFunctionCall(token, data.standards.c) and token.astOperand1 and token.astOperand1.function:
19462106
functionDeclaration = token.astOperand1.function
19472107

19482108
if functionDeclaration.tokenDef:
@@ -3269,7 +3429,7 @@ def misra_16_7(self, data):
32693429

32703430
def misra_17_1(self, data):
32713431
for token in data.tokenlist:
3272-
if isFunctionCall(token) and token.astOperand1.str in (
3432+
if isFunctionCall(token, data.standards.c) and token.astOperand1.str in (
32733433
'va_list', 'va_arg', 'va_start', 'va_end', 'va_copy'):
32743434
self.reportError(token, 17, 1)
32753435
elif token.str == 'va_list':
@@ -3338,7 +3498,7 @@ def misra_17_3(self, cfg):
33383498
end_token = token.next.link
33393499
while tok != end_token:
33403500
if tok.isName and tok.function is None and tok.valueType is None and tok.next.str == "(" and \
3341-
tok.next.valueType is None and not isKeyword(tok.str) and not isStdLibId(tok.str):
3501+
tok.next.valueType is None and not isKeyword(tok.str, cfg.standards.c) and not isStdLibId(tok.str, cfg.standards.c):
33423502
self.reportError(tok, 17, 3)
33433503
break
33443504
tok = tok.next
@@ -3391,7 +3551,7 @@ def misra_config(self, data):
33913551
continue
33923552
if tok.next.str == "(" or tok.str in ["EOF"]:
33933553
continue
3394-
if isKeyword(tok.str) or isStdLibId(tok.str):
3554+
if isKeyword(tok.str, data.standards.c) or isStdLibId(tok.str, data.standards.c):
33953555
continue
33963556
if tok.astParent is None:
33973557
continue
@@ -3656,7 +3816,7 @@ def misra_20_9(self, cfg):
36563816
break
36573817
for s in cond.E.split(' '):
36583818
if (s[0] >= 'A' and s[0] <= 'Z') or (s[0] >= 'a' and s[0] <= 'z'):
3659-
if isKeyword(s):
3819+
if isKeyword(s, cfg.standards.c):
36603820
continue
36613821
if s in defined:
36623822
continue
@@ -3790,7 +3950,7 @@ def misra_21_2(self, cfg):
37903950

37913951
def misra_21_3(self, data):
37923952
for token in data.tokenlist:
3793-
if isFunctionCall(token) and (token.astOperand1.str in ('malloc', 'calloc', 'realloc', 'free')):
3953+
if isFunctionCall(token, data.standards.c) and (token.astOperand1.str in ('malloc', 'calloc', 'realloc', 'free')):
37943954
self.reportError(token, 21, 3)
37953955

37963956
def misra_21_4(self, data):
@@ -3813,12 +3973,12 @@ def misra_21_6(self, data):
38133973

38143974
def misra_21_7(self, data):
38153975
for token in data.tokenlist:
3816-
if isFunctionCall(token) and (token.astOperand1.str in ('atof', 'atoi', 'atol', 'atoll')):
3976+
if isFunctionCall(token, data.standards.c) and (token.astOperand1.str in ('atof', 'atoi', 'atol', 'atoll')):
38173977
self.reportError(token, 21, 7)
38183978

38193979
def misra_21_8(self, data):
38203980
for token in data.tokenlist:
3821-
if isFunctionCall(token) and (token.astOperand1.str in ('abort', 'exit', 'getenv')):
3981+
if isFunctionCall(token, data.standards.c) and (token.astOperand1.str in ('abort', 'exit', 'getenv')):
38223982
self.reportError(token, 21, 8)
38233983

38243984
def misra_21_9(self, data):
@@ -3845,7 +4005,7 @@ def misra_21_12(self, data):
38454005
for token in data.tokenlist:
38464006
if token.str == 'fexcept_t' and token.isName:
38474007
self.reportError(token, 21, 12)
3848-
if isFunctionCall(token) and (token.astOperand1.str in (
4008+
if isFunctionCall(token, data.standards.c) and (token.astOperand1.str in (
38494009
'feclearexcept',
38504010
'fegetexceptflag',
38514011
'feraiseexcept',
@@ -3857,7 +4017,7 @@ def misra_21_14(self, data):
38574017
# buffers used in strcpy/strlen/etc function calls
38584018
string_buffers = []
38594019
for token in data.tokenlist:
3860-
if token.str[0] == 's' and isFunctionCall(token.next):
4020+
if token.str[0] == 's' and isFunctionCall(token.next, data.standards.c):
38614021
name, args = cppcheckdata.get_function_call_name_args(token)
38624022
if name is None:
38634023
continue

0 commit comments

Comments
 (0)