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

Function parse_dump_config

addons/y2038.py:214–299  ·  view source on GitHub ↗

Parse Y2038-related flags from cppcheck dump file configuration name. This function analyzes the cppcheck dump file configuration name (which contains preprocessor definitions extracted by cppcheck from project files like compile_commands.json) to extract Y2038-related definit

(config_name)

Source from the content-addressed store, hash-verified

212
213
214def parse_dump_config(config_name):
215 """
216 Parse Y2038-related flags from cppcheck dump file configuration name.
217
218 This function analyzes the cppcheck dump file configuration name (which contains
219 preprocessor definitions extracted by cppcheck from project files like compile_commands.json)
220 to extract Y2038-related definitions. It looks for _TIME_BITS, _USE_TIME_BITS64, and
221 _FILE_OFFSET_BITS definitions and validates their values.
222
223 Args:
224 config_name (str): The cppcheck configuration name from dump file
225 (e.g., "_TIME_BITS=64;_FILE_OFFSET_BITS=64")
226
227 Returns:
228 dict: Dictionary containing Y2038-related flag information with keys:
229 - 'time_bits_defined' (bool): Whether _TIME_BITS is defined
230 - 'time_bits_value' (int|None): Value of _TIME_BITS (None if not defined)
231 - 'use_time_bits64_defined' (bool): Whether _USE_TIME_BITS64 is defined
232 - 'file_offset_bits_defined' (bool): Whether _FILE_OFFSET_BITS is defined
233 - 'file_offset_bits_value' (int|None): Value of _FILE_OFFSET_BITS (None if not defined)
234
235 Example:
236 >>> parse_dump_config("_TIME_BITS=64;_FILE_OFFSET_BITS=64")
237 {
238 'time_bits_defined': True,
239 'time_bits_value': 64,
240 'use_time_bits64_defined': False,
241 'file_offset_bits_defined': True,
242 'file_offset_bits_value': 64
243 }
244 """
245 result = {
246 'time_bits_defined': False,
247 'time_bits_value': None,
248 'use_time_bits64_defined': False,
249 'file_offset_bits_defined': False,
250 'file_offset_bits_value': None
251 }
252
253 if not config_name:
254 return result
255
256 try:
257 # Check for _TIME_BITS=64 (correct value)
258 if re_flag_time_bits_64.search(config_name):
259 result['time_bits_defined'] = True
260 result['time_bits_value'] = Y2038_SAFE_TIME_BITS
261 else:
262 # Check for _TIME_BITS=other_value
263 match = re_flag_time_bits.search(config_name)
264 if match:
265 result['time_bits_defined'] = True
266 try:
267 result['time_bits_value'] = int(match.group(1))
268 except (ValueError, IndexError):
269 # Malformed _TIME_BITS value, treat as undefined
270 result['time_bits_defined'] = False
271 result['time_bits_value'] = None

Callers 3

test_parse_dump_configFunction · 0.90
check_y2038_safeFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_parse_dump_configFunction · 0.72