VirtualBox

Changeset 99896 in vbox


Ignore:
Timestamp:
May 22, 2023 11:41:57 AM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
157539
Message:

VMM/SSM: Added SSM_GET_STD_ENUM32_RET for automatically validating enum range using the standard INVALID and END values. bugref:10369

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/include/VBox/vmm/ssm.h

    r98103 r99896  
    13411341    } while (0)
    13421342
     1343/** Wrapper around SSMR3GetU32 for simplifying getting standard conforming enum
     1344 * values saved as uint32_t.  (The valid ragne is between the _INVALID and
     1345 * _END values.) */
     1346# define SSM_GET_STD_ENUM32_RET(a_pSSM, a_enmDst, a_EnumType) \
     1347    do { \
     1348        uint32_t u32GetEnumTmp = 0; \
     1349        int rcGetEnum32Tmp = SSMR3GetU32((a_pSSM), &u32GetEnumTmp); \
     1350        AssertRCReturn(rcGetEnum32Tmp, rcGetEnum32Tmp); \
     1351        a_EnumType enmTmp = (a_EnumType)u32GetEnumTmp; \
     1352        AssertCompile(sizeof(a_EnumType) == sizeof(u32GetEnumTmp)); \
     1353        if (RT_LIKELY(enmTmp > RT_CONCAT(a_EnumType,_INVALID) && enmTmp < RT_CONCAT(a_EnumType,_END))) \
     1354            (a_enmDst) = (a_EnumType)u32GetEnumTmp; \
     1355        else \
     1356            return SSMR3SetLoadError(a_pSSM, VERR_SSM_ENUM_VALUE_OUT_OF_RANGE, RT_SRC_POS, \
     1357                                     "The value for '%s' is out of range: %d (" #a_EnumType "_INVALID=%d, " #a_EnumType "_END=%d)", \
     1358                                     #a_enmDst, u32GetEnumTmp, RT_CONCAT(a_EnumType,_INVALID), RT_CONCAT(a_EnumType,_END)); \
     1359    } while (0)
     1360
    13431361/** @} */
    13441362
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette