MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / DeserializeFloatInlined

Function DeserializeFloatInlined

Library/OcGuardLib/Ubsan.c:1448–1480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1446}
1447
1448static void
1449DeserializeFloatInlined(char *pBuffer, size_t zBUfferLength, struct CTypeDescriptor *pType, unsigned long ulNumber)
1450{
1451 float F;
1452 double D;
1453 uint32_t U32;
1454
1455 ASSERT(pBuffer);
1456 ASSERT(zBUfferLength > 0);
1457 ASSERT(pType);
1458 ASSERT(sizeof(F) == sizeof(uint32_t));
1459 ASSERT(sizeof(D) == sizeof(uint64_t));
1460
1461 switch (zDeserializeTypeWidth(pType)) {
1462 case WIDTH_64:
1463 memcpy(&D, &ulNumber, sizeof(double));
1464 snprintf(pBuffer, zBUfferLength, "%g", D);
1465 break;
1466 case WIDTH_32:
1467 /*
1468 * On supported platforms sizeof(float)==sizeof(uint32_t)
1469 * unsigned long is either 32 or 64-bit, cast it to 32-bit
1470 * value in order to call memcpy(3) in an Endian-aware way.
1471 */
1472 U32 = STATIC_CAST(uint32_t, ulNumber);
1473 memcpy(&F, &U32, sizeof(float));
1474 snprintf(pBuffer, zBUfferLength, "%g", F);
1475 break;
1476 case WIDTH_16:
1477 snprintf(pBuffer, zBUfferLength, "Undecoded-16-bit-Floating-Type (%#04" PRIx16 ")", STATIC_CAST(uint16_t, ulNumber));
1478 break;
1479 }
1480}
1481#endif
1482
1483static longest

Callers 1

DeserializeNumberFloatFunction · 0.85

Calls 3

zDeserializeTypeWidthFunction · 0.85
snprintfFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected