MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / check_y2038_safe

Function check_y2038_safe

addons/y2038.py:302–576  ·  view source on GitHub ↗

Main function to check Y2038 safety of C/C++ code from cppcheck dump files. This function performs comprehensive Y2038 analysis including: 1. Extraction of Y2038-related compiler flags from cppcheck dump file configuration 2. Analysis of source code preprocessor directives 3. W

(dumpfile, quiet=False)

Source from the content-addressed store, hash-verified

300
301
302def check_y2038_safe(dumpfile, quiet=False):
303 """
304 Main function to check Y2038 safety of C/C++ code from cppcheck dump files.
305
306 This function performs comprehensive Y2038 analysis including:
307 1. Extraction of Y2038-related compiler flags from cppcheck dump file configuration
308 2. Analysis of source code preprocessor directives
309 3. Warning suppression when proper Y2038 configuration is detected
310 4. Reporting of Y2038-unsafe symbols and configurations
311
312 The function implements a priority-based approach for Y2038 flag detection:
313 - Dump file configuration (from cppcheck's project parsing - highest priority)
314 - Source code #define directives (fallback)
315
316 Warning suppression occurs when both _TIME_BITS=64 AND _FILE_OFFSET_BITS=64
317 are detected from any source. When warnings are suppressed, an informational
318 message is displayed indicating the configuration source and suppression count.
319
320 Args:
321 dumpfile (str): Path to the cppcheck XML dump file (.dump extension)
322 quiet (bool, optional): If True, suppress informational messages. Defaults to False.
323
324 Returns:
325 bool: True if code is Y2038-safe, False if Y2038 issues were detected
326
327 Raises:
328 Exception: May raise exceptions from cppcheckdata parsing or file I/O operations
329
330 Example:
331 >>> check_y2038_safe("test.c.dump") # Normal operation
332 True
333 >>> check_y2038_safe("test.c.dump", quiet=True) # Suppress info messages
334 False
335 """
336 # Assume that the code is Y2038 safe until proven otherwise
337 y2038safe = True
338 # load XML from .dump file
339 data = cppcheckdata.CppcheckData(dumpfile)
340
341 srcfile = data.files[0]
342
343 for cfg in data.iterconfigurations():
344 if not quiet:
345 print('Checking %s, config %s...' % (srcfile, cfg.name))
346 safe_ranges = []
347 safe = -1
348 time_bits_defined = False
349 srclinenr = 0
350
351 # Priority-based flag detection: dump file configuration > source code directives
352 # 1. Check dump file configuration (from cppcheck's project parsing - highest priority)
353 dump_config_flags = parse_dump_config(cfg.name)
354 # Initialize effective flags with dump file configuration
355 effective_flags = {
356 'time_bits_defined': dump_config_flags['time_bits_defined'],
357 'time_bits_value': dump_config_flags['time_bits_value'],
358 'use_time_bits64_defined': dump_config_flags['use_time_bits64_defined'],
359 'file_offset_bits_defined': dump_config_flags['file_offset_bits_defined'],

Callers 6

test_1_bad_time_bitsFunction · 0.90
test_2_no_time_bitsFunction · 0.90
test_3_no_use_time_bitsFunction · 0.90
test_4_goodFunction · 0.90
test_5_goodFunction · 0.90
y2038.pyFile · 0.85

Calls 5

iterconfigurationsMethod · 0.95
parse_dump_configFunction · 0.85
typeFunction · 0.50
reportErrorMethod · 0.45
matchMethod · 0.45

Tested by 5

test_1_bad_time_bitsFunction · 0.72
test_2_no_time_bitsFunction · 0.72
test_3_no_use_time_bitsFunction · 0.72
test_4_goodFunction · 0.72
test_5_goodFunction · 0.72