Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util: rz_endian cleanup and documentation (#3900)
* librz: rename function parameter The function parameter is renamed from _dest to dest. In the body of the function, the identifiers _dest and dest are swapped accordingly. This makes these functions have the same parameter name as all others of the same kind in the header. * librz: add swap macros when builtins missing The rz_swap_ macros are only defined when the compiler builtins are available. We define them in case they are not for uniformity of presence in the preprocessor namespace. * librz: add documentation for rz_endian.h Every function and macro is documented except for the signed swap macros. * librz: return max value in read if parameter is NULL The read functions in rz_endian.h sometimes returned the MAX value when the source parameter was NULL and sometimes didn't. For example, compare rz_read_be16 which doesn't check NULL and rz_read_le16 which does. We fix this by inserting checks for NULL in every integer read function. We also insert these checks for the floating-point read functions. They also too sometimes checked for NULL indirectly by calling the corresponding integer read functions, but the read functions with the offset parameter did not check for NULL. Separately, The NULL checks in rz_read_le8 and rz_read_me8 were removed because they were duplicate; they call rz_read_ble8 which checks for NULL. * librz: add documentation in swap functions for NULL source parameter The case where the source parameter is NULL is documented in all the read functions in rz_endian.h A mistake in the documentation of rz_read_at_ble64 is fixed; it incorrectly mentioned 128-bit instead of 64-bit integers. * librz: add missing 24-bit macros The 24-bit macros for minimum and maximum value are added. * librz: add missing endianness functions For the readers and writers, certain endianness and bit number combinations were missing. Some missing big-endian, little-endian, middle-endian functions as well as helper functions are added. The documentation of some read blue functions is corrected to mention "specified" order instead of "big-endian". * librz: fixing some compiler errors from typos * librz: remove UT24 macros We remove the UT24_ macros due to PR review. * librz: replace UT24_MAX with UT32_MAX It is better to return the maximum value held by the return type instead of returning a max 24-bit value. * test: add more rz_endian tests All the integral endian functions for read and write are ran through some basic tests. * librz: remove unused internal functions The signed rz_swap functions are removed because they are not used anywhere in the source code. They are duplicates of the corresponding unsigned functions. Moreover, the rz_swap_st16 function has an incorrect implementation when the compiler builtin is missing. Instead of fixing, adding documentation, and unit tests, which means we would also need to create an environment with the compiler builtin check undefined, we simply remove them, because they are not used anywhere. * librz: remove unnecessary define macros These macros were added during the PR and were requested to be removed again. * test: fix MSVC complaining on erroneous commas The string literal #__VA_ARGS__ is equal to "" in a conforming implementation when there is an empty list of variadic arguments. On MSVC 2017, it is completely missing, causing an error. These issues appear to have been fixed in VS2019 v16.5 and later using the /Zc:preprocessor compiler switch and in Visual Studio 2017 version 15.8 using /experimental:preprocessor. In any case, we use string concatenating to force an empty string to appear even if #__VA_ARGS__ is missing.
- Loading branch information