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)
| 300 | |
| 301 | |
| 302 | def 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'], |