all: minor cleanups
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
template <class T>
|
||||
inline
|
||||
typename std::enable_if<std::is_pointer<T>::value && !upx::is_bounded_array<T>::value, T>::type
|
||||
raw_bytes(T ptr, size_t size_in_bytes) {
|
||||
raw_bytes(T ptr, size_t size_in_bytes) may_throw {
|
||||
if (size_in_bytes > 0) {
|
||||
if very_unlikely (ptr == nullptr)
|
||||
throwCantPack("raw_bytes unexpected NULL ptr");
|
||||
@@ -53,7 +53,7 @@ template <class T>
|
||||
inline typename std::enable_if<std::is_pointer<T>::value && !upx::is_bounded_array<T>::value &&
|
||||
!std::is_void<typename std::remove_pointer<T>::type>::value,
|
||||
T>::type
|
||||
raw_index_bytes(T ptr, size_t index, size_t size_in_bytes) {
|
||||
raw_index_bytes(T ptr, size_t index, size_t size_in_bytes) may_throw {
|
||||
typedef typename std::remove_pointer<T>::type element_type;
|
||||
if very_unlikely (ptr == nullptr)
|
||||
throwCantPack("raw_index_bytes unexpected NULL ptr");
|
||||
@@ -66,7 +66,7 @@ raw_index_bytes(T ptr, size_t index, size_t size_in_bytes) {
|
||||
|
||||
// same for bounded arrays
|
||||
template <class T, size_t N>
|
||||
inline T *raw_bytes(T (&array)[N], size_t size_in_bytes) {
|
||||
inline T *raw_bytes(T (&array)[N], size_t size_in_bytes) may_throw {
|
||||
typedef T element_type;
|
||||
if very_unlikely (size_in_bytes > mem_size(sizeof(element_type), N))
|
||||
throwCantPack("raw_bytes out of range");
|
||||
@@ -74,7 +74,7 @@ inline T *raw_bytes(T (&array)[N], size_t size_in_bytes) {
|
||||
}
|
||||
|
||||
template <class T, size_t N>
|
||||
inline T *raw_index_bytes(T (&array)[N], size_t index, size_t size_in_bytes) {
|
||||
inline T *raw_index_bytes(T (&array)[N], size_t index, size_t size_in_bytes) may_throw {
|
||||
typedef T element_type;
|
||||
return raw_bytes(array, mem_size(sizeof(element_type), index, size_in_bytes)) + index;
|
||||
}
|
||||
|
||||
+33
-29
@@ -31,25 +31,25 @@
|
||||
// UPX version of string functions, with assertions and sane limits
|
||||
**************************************************************************/
|
||||
|
||||
upx_rsize_t upx_safe_strlen(const char *) may_throw;
|
||||
|
||||
// info: snprintf() returns length and NOT size, but max_size is indeed size (incl NUL)
|
||||
|
||||
int upx_safe_vsnprintf(char *str, upx_rsize_t max_size, const char *format, va_list ap);
|
||||
int upx_safe_vsnprintf(char *str, upx_rsize_t max_size, const char *format, va_list ap) may_throw;
|
||||
int upx_safe_snprintf(char *str, upx_rsize_t max_size, const char *format, ...)
|
||||
attribute_format(3, 4);
|
||||
may_throw attribute_format(3, 4);
|
||||
|
||||
// malloc's *ptr
|
||||
int upx_safe_vasprintf(char **ptr, const char *format, va_list ap);
|
||||
int upx_safe_asprintf(char **ptr, const char *format, ...) attribute_format(2, 3);
|
||||
int upx_safe_vasprintf(char **ptr, const char *format, va_list ap) may_throw;
|
||||
int upx_safe_asprintf(char **ptr, const char *format, ...) may_throw attribute_format(2, 3);
|
||||
|
||||
// returns a malloc'd pointer
|
||||
char *upx_safe_xprintf(const char *format, ...) attribute_format(1, 2);
|
||||
|
||||
upx_rsize_t upx_safe_strlen(const char *);
|
||||
char *upx_safe_xprintf(const char *format, ...) may_throw attribute_format(1, 2);
|
||||
|
||||
// noexcept variants (these use "assert_noexcept")
|
||||
upx_rsize_t upx_safe_strlen_noexcept(const char *) noexcept;
|
||||
int upx_safe_vsnprintf_noexcept(char *str, upx_rsize_t max_size, const char *format,
|
||||
va_list ap) noexcept;
|
||||
upx_rsize_t upx_safe_strlen_noexcept(const char *) noexcept;
|
||||
|
||||
// globally redirect some functions
|
||||
#undef strlen
|
||||
@@ -66,28 +66,32 @@ upx_rsize_t upx_safe_strlen_noexcept(const char *) noexcept;
|
||||
// some uchar string support functions to avoid casts
|
||||
**************************************************************************/
|
||||
|
||||
forceinline uchar *strcpy(uchar *s1, const uchar *s2) {
|
||||
return (uchar *) strcpy((char *) s1, (const char *) s2);
|
||||
}
|
||||
|
||||
forceinline int strcmp(const uchar *s1, const char *s2) { return strcmp((const char *) s1, s2); }
|
||||
forceinline int strcmp(const char *s1, const uchar *s2) { return strcmp(s1, (const char *) s2); }
|
||||
forceinline int strcmp(const uchar *s1, const uchar *s2) {
|
||||
return strcmp((const char *) s1, (const char *) s2);
|
||||
}
|
||||
|
||||
forceinline int strcasecmp(const uchar *s1, const char *s2) {
|
||||
return strcasecmp((const char *) s1, s2);
|
||||
}
|
||||
forceinline int strcasecmp(const char *s1, const uchar *s2) {
|
||||
return strcasecmp(s1, (const char *) s2);
|
||||
}
|
||||
forceinline int strcasecmp(const uchar *s1, const uchar *s2) {
|
||||
return strcasecmp((const char *) s1, (const char *) s2);
|
||||
}
|
||||
|
||||
forceinline upx_rsize_t upx_safe_strlen(const uchar *s) {
|
||||
forceinline upx_rsize_t upx_safe_strlen(const uchar *s) may_throw {
|
||||
return upx_safe_strlen((const char *) s);
|
||||
}
|
||||
|
||||
forceinline uchar *strcpy(uchar *s1, const uchar *s2) noexcept {
|
||||
return (uchar *) strcpy((char *) s1, (const char *) s2);
|
||||
}
|
||||
|
||||
forceinline int strcmp(const uchar *s1, const char *s2) noexcept {
|
||||
return strcmp((const char *) s1, s2);
|
||||
}
|
||||
forceinline int strcmp(const char *s1, const uchar *s2) noexcept {
|
||||
return strcmp(s1, (const char *) s2);
|
||||
}
|
||||
forceinline int strcmp(const uchar *s1, const uchar *s2) noexcept {
|
||||
return strcmp((const char *) s1, (const char *) s2);
|
||||
}
|
||||
|
||||
forceinline int strcasecmp(const uchar *s1, const char *s2) noexcept {
|
||||
return strcasecmp((const char *) s1, s2);
|
||||
}
|
||||
forceinline int strcasecmp(const char *s1, const uchar *s2) noexcept {
|
||||
return strcasecmp(s1, (const char *) s2);
|
||||
}
|
||||
forceinline int strcasecmp(const uchar *s1, const uchar *s2) noexcept {
|
||||
return strcasecmp((const char *) s1, (const char *) s2);
|
||||
}
|
||||
|
||||
/* vim:set ts=4 sw=4 et: */
|
||||
|
||||
Reference in New Issue
Block a user