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

Function id_string_i

lib/utils.h:332–365  ·  view source on GitHub ↗

* @brief get id string. i.e. for dump files * it will be a hexadecimal output. */

Source from the content-addressed store, hash-verified

330 * it will be a hexadecimal output.
331 */
332static inline std::string id_string_i(std::uintptr_t l)
333{
334 if (!l)
335 return "0";
336
337 static constexpr int ptr_size = sizeof(void*);
338
339 // two characters of each byte / contains terminating \0
340 static constexpr int buf_size = (ptr_size * 2) + 1;
341
342 char buf[buf_size];
343
344 // needs to be signed so we don't underflow in padding loop
345 int idx = buf_size - 1;
346 buf[idx] = '\0';
347
348 while (l != 0)
349 {
350 char c;
351 const std::uintptr_t temp = l % 16; // get the remainder
352 if (temp < 10) {
353 // 0-9
354 c = '0' + temp;
355 }
356 else {
357 // a-f
358 c = 'a' + (temp - 10);
359 }
360 buf[--idx] = c; // store in reverse order
361 l = l / 16;
362 }
363
364 return &buf[idx];
365}
366
367static inline std::string id_string(const void* p)
368{

Callers 2

id_stringFunction · 0.85
id_stringMethod · 0.85

Calls

no outgoing calls

Tested by 1

id_stringMethod · 0.68