summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/htssafe.h24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/htssafe.h b/src/htssafe.h
index d21107c..3451d26 100644
--- a/src/htssafe.h
+++ b/src/htssafe.h
@@ -130,12 +130,24 @@ static HTS_UNUSED void htssafe_compile_time_check_(void) {
*/
#define strncatbuff(A, B, N) \
( HTS_IS_NOT_CHAR_BUFFER(A) \
- ? strncat(A, B, N) \
+ ? ( (N) != (size_t) -1 ? strncat(A, B, N) : strcat(A, B) ) \
: strncat_safe_(A, sizeof(A), B, \
HTS_IS_NOT_CHAR_BUFFER(B) ? (size_t) -1 : sizeof(B), N, \
"overflow while appending '" #B "' to '"#A"'", __FILE__, __LINE__) )
/**
+ * Append characters of "B" to "A".
+ * If "A" is a char[] variable whose size is not sizeof(char*), then the size
+ * is assumed to be the capacity of this array.
+ */
+#define strcatbuff(A, B) \
+ ( HTS_IS_NOT_CHAR_BUFFER(A) \
+ ? strcat(A, B) \
+ : strncat_safe_(A, sizeof(A), B, \
+ HTS_IS_NOT_CHAR_BUFFER(B) ? (size_t) -1 : sizeof(B), (size_t) -1, \
+ "overflow while appending '" #B "' to '"#A"'", __FILE__, __LINE__) )
+
+/**
* Copy characters from "B" to "A".
* If "A" is a char[] variable whose size is not sizeof(char*), then the size
* is assumed to be the capacity of this array.
@@ -147,15 +159,6 @@ static HTS_UNUSED void htssafe_compile_time_check_(void) {
HTS_IS_NOT_CHAR_BUFFER(B) ? (size_t) -1 : sizeof(B), \
"overflow while copying '" #B "' to '"#A"'", __FILE__, __LINE__) )
-/* note: "size_t is an unsigned integral type" */
-
-/**
- * Append characters of "B" to "A".
- * If "A" is a char[] variable whose size is not sizeof(char*), then the size
- * is assumed to be the capacity of this array.
- */
-#define strcatbuff(A, B) strncatbuff(A, B, (size_t) -1)
-
/**
* Append characters of "B" to "A", "A" having a maximum capacity of "S".
*/
@@ -188,6 +191,7 @@ static HTS_INLINE HTS_UNUSED char* strncat_safe_(char *const dest, const size_t
const char *exp, const char *file, int line) {
const size_t source_len = strlen_safe_(source, sizeof_source, file, line);
const size_t dest_len = strlen_safe_(dest, sizeof_dest, file, line);
+ /* note: "size_t is an unsigned integral type" ((size_t) -1 is positive) */
const size_t source_copy = source_len <= n ? source_len : n;
const size_t dest_final_len = dest_len + source_copy;
assertf__(dest_final_len < sizeof_dest, exp, file, line);