VirtualBox

儲存庫 vbox 的更動 81869


忽略:
時間撮記:
2019-11-15 下午12:45:55 (5 年 以前)
作者:
vboxsync
svn:sync-xref-src-repo-rev:
134663
訊息:

iprt/cdefs.h: Adding RT_SAFE_SUBSCRIPT (with variations) for safer array subscription in places where we need to be paranoid. bugref:9218

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/include/iprt/cdefs.h

    r81649 r81869  
    24762476#define RT_ELEMENTS(aArray)                     ( sizeof(aArray) / sizeof((aArray)[0]) )
    24772477
     2478/** @def RT_SAFE_SUBSCRIPT
     2479 * Safe array subscript using modulo and size_t cast.
     2480 * @param   a_Array     The array.
     2481 * @param   a_idx       The array index, cast to size_t to ensure unsigned.
     2482 */
     2483#define RT_SAFE_SUBSCRIPT(a_Array, a_idx)      (a_Array)[(size_t)(a_idx) % RT_ELEMENTS(a_Array)]
     2484
     2485/** @def RT_SAFE_SUBSCRIPT32
     2486 * Safe array subscript using modulo and uint32_t cast.
     2487 * @param   a_Array     The array.
     2488 * @param   a_idx       The array index, cast to size_t to ensure unsigned.
     2489 * @note    Only consider using this if array size is not power of two.
     2490 */
     2491#define RT_SAFE_SUBSCRIPT32(a_Array, a_idx)    (a_Array)[(uint32_t)(a_idx) % RT_ELEMENTS(a_Array)]
     2492
     2493/** @def RT_SAFE_SUBSCRIPT16
     2494 * Safe array subscript using modulo and uint16_t cast.
     2495 * @param   a_Array     The array.
     2496 * @param   a_idx       The array index, cast to size_t to ensure unsigned.
     2497 * @note    Only consider using this if array size is not power of two.
     2498 */
     2499#define RT_SAFE_SUBSCRIPT16(a_Array, a_idx)     (a_Array)[(uint16_t)(a_idx) % RT_ELEMENTS(a_Array)]
     2500
     2501/** @def RT_SAFE_SUBSCRIPT8
     2502 * Safe array subscript using modulo and uint8_t cast.
     2503 * @param   a_Array     The array.
     2504 * @param   a_idx       The array index, cast to size_t to ensure unsigned.
     2505 * @note    Only consider using this if array size is not power of two.
     2506 */
     2507#define RT_SAFE_SUBSCRIPT8(a_Array, a_idx)      (a_Array)[(uint8_t)(a_idx) % RT_ELEMENTS(a_Array)]
     2508
     2509/** @def RT_SAFE_SUBSCRIPT_NC
     2510 * Safe array subscript using modulo but no cast.
     2511 * @param   a_Array     The array.
     2512 * @param   a_idx       The array index - assumes unsigned type.
     2513 * @note    Only consider using this if array size is not power of two.
     2514 */
     2515#define RT_SAFE_SUBSCRIPT_NC(a_Array, a_idx)    (a_Array)[(a_idx) % RT_ELEMENTS(a_Array)]
     2516
    24782517/** @def RT_FLEXIBLE_ARRAY
    24792518 * What to up inside the square brackets when declaring a structure member
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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