Skip to content

Commit

Permalink
Add more string test cases.
Browse files Browse the repository at this point in the history
This adds test cases for the rest of our ASCII string functions.  While
doing so, it fixes two minor bugs:
- strcasecmp() now handles utf8 correctly
- strncpy() no longer does the stpncpy() behavior of clearing leftover
  buffer

Signed-off-by: Peter Jones <pjones@redhat.com>
  • Loading branch information
vathpela committed Mar 10, 2021
1 parent 8d006f5 commit c722a59
Show file tree
Hide file tree
Showing 3 changed files with 854 additions and 76 deletions.
14 changes: 14 additions & 0 deletions include/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,20 @@ extern int debug;
} \
})

#define assert_negative_goto(a, label, fmt, ...) \
({ \
int rc_ = assert_negative_as_expr(a, -1, fmt, ##__VA_ARGS__); \
if (rc_ != 0) \
goto label; \
})

#define assert_positive_goto(a, label, fmt, ...) \
({ \
int rc_ = assert_positive_as_expr(a, -1, fmt, ##__VA_ARGS__); \
if (rc_ != 0) \
goto label; \
})

#define test(x, ...) \
({ \
int rc; \
Expand Down
5 changes: 3 additions & 2 deletions lib/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define strcasecmp shim_strcasecmp
#define strrchr shim_strrchr
#define strlen shim_strlen
#define strnlen shim_strnlen
#define strcpy shim_strcpy
#define strncpy shim_strncpy
#define strdup shim_strdup
Expand Down Expand Up @@ -93,7 +94,7 @@ strncasecmp(const char *s1p, const char *s2p, size_t n)
int
strcasecmp(const char *str1, const char *str2)
{
char c1, c2;
uint8_t c1, c2;

c1 = toupper(*str1);
c2 = toupper(*str2);
Expand Down Expand Up @@ -155,7 +156,7 @@ strncpy(char *dest, const char *src, size_t n)

for (i = 0; i < n && src[i] != '\0'; i++)
dest[i] = src[i];
for (; i < n; i++)
if (i < n)
dest[i] = '\0';

return dest;
Expand Down
Loading

0 comments on commit c722a59

Please sign in to comment.