diff --git a/.gitignore b/.gitignore index 60bfe41..8ee853d 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,9 @@ x64/ build/ [Bb]in/ [Oo]bj/ +/libsafestring.a +/objtest +/safestringtest # MSTest test Results [Tt]est[Rr]esult*/ diff --git a/makefile b/makefile index f7cc268..d931f15 100644 --- a/makefile +++ b/makefile @@ -1,59 +1,82 @@ IDIR = include MKDIR_P = mkdir -p CC=gcc -CFLAGS=-I$(IDIR) -fstack-protector-strong -fPIE -fPIC -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -LDFLAGS=-z noexecstack -z relo -z now +CFLAGS := -I${IDIR} -fstack-protector-strong -fPIE -fPIC -O2 -MMD +CFLAGS += -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wformat-security +CFLAGS += -Wmissing-prototypes -Wstrict-prototypes +LDFLAGS=-z noexecstack -z now ODIR=obj OTDIR=objtest SRCDIR=safeclib TESTDIR=unittests - -_DEPS = safe_lib_errno.h safe_lib.h safe_str_lib.h safe_types.h.in safe_lib_errno.h.in safe_mem_lib.h safe_types.h - -_ODEPS = mem_primitives_lib.h safeclib_private.h safe_mem_constraint.h safe_str_constraint.h - -all: directories libsafestring.a safestringtest - - -DEPS = $(addprefix $(IDIR)/,$(_DEPS)) -ODEPS = $(addprefix $(SRCDIR)/,$(_ODEPS)) - - -_CLIB = abort_handler_s.c stpcpy_s.c strlastsame_s.c ignore_handler_s.c stpncpy_s.c strljustify_s.c memcmp16_s.c strcasecmp_s.c strncat_s.c memcmp32_s.c strcasestr_s.c strncpy_s.c memcmp_s.c strcat_s.c strnlen_s.c memcpy16_s.c strcmpfld_s.c strnterminate_s.c memcpy32_s.c strcmp_s.c strpbrk_s.c memcpy_s.c strcpyfldin_s.c strprefix_s.c memmove16_s.c strcpyfldout_s.c strremovews_s.c memmove32_s.c strcpyfld_s.c strspn_s.c memmove_s.c strcpy_s.c strstr_s.c mem_primitives_lib.c strcspn_s.c strtok_s.c strfirstchar_s.c strtolowercase_s.c memset16_s.c strfirstdiff_s.c strtouppercase_s.c memset32_s.c strfirstsame_s.c strzero_s.c memset_s.c strisalphanumeric_s.c wcpcpy_s.c memzero16_s.c strisascii_s.c wcscat_s.c memzero32_s.c strisdigit_s.c wcscpy_s.c memzero_s.c strishex_s.c wcsncat_s.c strislowercase_s.c wcsncpy_s.c safe_mem_constraint.c strismixedcase_s.c wcsnlen_s.c strispassword_s.c wmemcmp_s.c safe_str_constraint.c strisuppercase_s.c wmemcpy_s.c strlastchar_s.c wmemmove_s.c snprintf_support.c strlastdiff_s.c wmemset_s.c +.PHONY: all +all: libsafestring.a safestringtest + +_CLIB := abort_handler_s.c stpcpy_s.c strlastsame_s.c ignore_handler_s.c +_CLIB += stpncpy_s.c strljustify_s.c memcmp16_s.c strcasecmp_s.c strncat_s.c +_CLIB += memcmp32_s.c strcasestr_s.c strncpy_s.c memcmp_s.c strcat_s.c +_CLIB += strnlen_s.c memcpy16_s.c strcmpfld_s.c strnterminate_s.c memcpy32_s.c +_CLIB += strcmp_s.c strpbrk_s.c memcpy_s.c strcpyfldin_s.c strprefix_s.c +_CLIB += memmove16_s.c strcpyfldout_s.c strremovews_s.c memmove32_s.c +_CLIB += strcpyfld_s.c strspn_s.c memmove_s.c strcpy_s.c strstr_s.c +_CLIB += mem_primitives_lib.c strcspn_s.c strtok_s.c strfirstchar_s.c +_CLIB += strtolowercase_s.c memset16_s.c strfirstdiff_s.c strtouppercase_s.c +_CLIB += memset32_s.c strfirstsame_s.c strzero_s.c memset_s.c +_CLIB += strisalphanumeric_s.c wcpcpy_s.c memzero16_s.c strisascii_s.c +_CLIB += wcscat_s.c memzero32_s.c strisdigit_s.c wcscpy_s.c memzero_s.c +_CLIB += strishex_s.c wcsncat_s.c strislowercase_s.c wcsncpy_s.c +_CLIB += safe_mem_constraint.c strismixedcase_s.c wcsnlen_s.c +_CLIB += strispassword_s.c wmemcmp_s.c safe_str_constraint.c +_CLIB += strisuppercase_s.c wmemcpy_s.c strlastchar_s.c wmemmove_s.c +_CLIB += snprintf_support.c strlastdiff_s.c wmemset_s.c _TLIST = $(addprefix $(ODIR)/,$(_CLIB)) OBJ = $(patsubst %.c,%.o,$(_TLIST)) CLIB =$(addprefix $(SRCDIR)/,$(_CLIB)) - -$(ODIR)/%.o: $(SRCDIR)/%.c $(DEPS) $(ODEPS) +${ODIR}/%.o: ${SRCDIR}/%.c | ${ODIR} $(CC) $(LDFLAGS) -c -o $@ $< $(CFLAGS) libsafestring.a: $(OBJ) ar rcs $@ $^ - -_TESTFUNCS = Safe_String_UnitTestMain.c test_strcmp_s.c test_strnlen_s.c test_memcmp16_s.c test_strcpyfldin_s.c test_strnterminate_s.c test_memcmp32_s.c test_strcpyfldout_s.c test_strpbrk_s.c test_memcmp_s.c test_strcpyfld_s.c test_strprefix_s.c test_memcpy16_s.c test_strcpy_s.c test_strremovews_s.c test_memcpy32_s.c test_strcspn_s.c test_strspn_s.c test_memcpy_s.c test_strfirstchar_s.c test_strstr_s.c test_memmove16_s.c test_strfirstdiff_s.c test_strtok_s.c test_memmove32_s.c test_strfirstsame_s.c test_strtolowercase_s.c test_memmove_s.c test_strisalphanumeric_s.c test_strtouppercase_s.c test_memset16_s.c test_strisascii_s.c test_strzero_s.c test_memset32_s.c test_strisdigit_s.c test_wcpcpy_s.c test_memset_s.c test_strishex_s.c test_wcscat_s.c test_memzero16_s.c test_strislowercase_s.c test_wcscpy_s.c test_memzero32_s.c test_strismixed_s.c test_wcsncat_s.c test_memzero_s.c test_strispassword_s.c test_wcsncpy_s.c test_strisuppercase_s.c test_wcsnlen_s.c test_stpcpy_s.c test_strlastchar_s.c test_wmemcmp_s.c test_stpncpy_s.c test_strlastdiff_s.c test_wmemcpy_s.c test_strcasecmp_s.c test_strlastsame_s.c test_wmemmove_s.c test_strcasestr_s.c test_strljustify_s.c test_wmemset_s.c test_strcat_s.c test_strncat_s.c test_strcmpfld_s.c test_strncpy_s.c +_TESTFUNCS := Safe_String_UnitTestMain.c test_strcmp_s.c test_strnlen_s.c +_TESTFUNCS += test_memcmp16_s.c test_strcpyfldin_s.c test_strnterminate_s.c +_TESTFUNCS += test_memcmp32_s.c test_strcpyfldout_s.c test_strpbrk_s.c +_TESTFUNCS += test_memcmp_s.c test_strcpyfld_s.c test_strprefix_s.c +_TESTFUNCS += test_memcpy16_s.c test_strcpy_s.c test_strremovews_s.c +_TESTFUNCS += test_memcpy32_s.c test_strcspn_s.c test_strspn_s.c +_TESTFUNCS += test_memcpy_s.c test_strfirstchar_s.c test_strstr_s.c +_TESTFUNCS += test_memmove16_s.c test_strfirstdiff_s.c test_strtok_s.c +_TESTFUNCS += test_memmove32_s.c test_strfirstsame_s.c test_strtolowercase_s.c +_TESTFUNCS += test_memmove_s.c test_strisalphanumeric_s.c +_TESTFUNCS += test_strtouppercase_s.c test_memset16_s.c test_strisascii_s.c +_TESTFUNCS += test_strzero_s.c test_memset32_s.c test_strisdigit_s.c +_TESTFUNCS += test_wcpcpy_s.c test_memset_s.c test_strishex_s.c test_wcscat_s.c +_TESTFUNCS += test_memzero16_s.c test_strislowercase_s.c test_wcscpy_s.c +_TESTFUNCS += test_memzero32_s.c test_strismixed_s.c test_wcsncat_s.c +_TESTFUNCS += test_memzero_s.c test_strispassword_s.c test_wcsncpy_s.c +_TESTFUNCS += test_strisuppercase_s.c test_wcsnlen_s.c test_stpcpy_s.c +_TESTFUNCS += test_strlastchar_s.c test_wmemcmp_s.c test_stpncpy_s.c +_TESTFUNCS += test_strlastdiff_s.c test_wmemcpy_s.c test_strcasecmp_s.c +_TESTFUNCS += test_strlastsame_s.c test_wmemmove_s.c test_strcasestr_s.c +_TESTFUNCS += test_strljustify_s.c test_wmemset_s.c test_strcat_s.c +_TESTFUNCS += test_strncat_s.c test_strcmpfld_s.c test_strncpy_s.c _TLIST2 = $(addprefix $(OTDIR)/,$(_TESTFUNCS)) TOBJ = $(patsubst %.c,%.o,$(_TLIST2)) TCLIB =$(addprefix $(TESTDIR)/,$(_TESTFUNCS)) -$(OTDIR)/%.o: $(TESTDIR)/%.c $(TESTDIR)/test_private.h +${OTDIR}/%.o: ${TESTDIR}/%.c ${TESTDIR}/test_private.h | ${OTDIR} $(CC) -c -o $@ $< $(CFLAGS) -safestringtest: directories libsafestring.a $(TOBJ) - $(CC) $(LDFLAGS) -static -o $@ $(TOBJ) libsafestring.a - - -.PHONY: directories - -directories: ${ODIR} ${OTDIR} +safestringtest: libsafestring.a $(TOBJ) | ${OTDIR} + $(CC) $(LDFLAGS) -o $@ $(TOBJ) libsafestring.a ${ODIR}: ${MKDIR_P} ${ODIR} @@ -64,6 +87,10 @@ ${OTDIR}: .PHONY: clean clean: - rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~ $(OTDIR)/*.o + rm -f *~ core ${INCDIR}/*~ + rm -rf ${ODIR} ${OTDIR} rm -f libsafestring.a rm -f safestringtest + +-include $(wildcard ${ODIR}/*.d) +-include $(wildcard ${OTDIR}/*.d) diff --git a/safeclib/abort_handler_s.c b/safeclib/abort_handler_s.c index d956bfd..97e11bd 100644 --- a/safeclib/abort_handler_s.c +++ b/safeclib/abort_handler_s.c @@ -65,7 +65,7 @@ * */ -void abort_handler_s(const char *msg, void *ptr, errno_t error) +void abort_handler_s(const char *msg, _UNUSED void *ptr, errno_t error) { slprintf("ABORT CONSTRAINT HANDLER: (%u) %s\n", error, (msg) ? msg : "Null message"); diff --git a/safeclib/ignore_handler_s.c b/safeclib/ignore_handler_s.c index 412e0cb..3e9b8c1 100644 --- a/safeclib/ignore_handler_s.c +++ b/safeclib/ignore_handler_s.c @@ -31,6 +31,12 @@ #include "safeclib_private.h" +#ifdef DEBUG +#define _DUNUSED +#else +#define _DUNUSED _UNUSED +#endif /* DEBUG */ + /** * NAME * ignore_handler_s @@ -62,7 +68,8 @@ * */ -void ignore_handler_s(const char *msg, void *ptr, errno_t error) +void ignore_handler_s(_DUNUSED const char *msg, _UNUSED void *ptr, + _DUNUSED errno_t error) { sldebug_printf("IGNORE CONSTRAINT HANDLER: (%u) %s\n", error, diff --git a/safeclib/mem_primitives_lib.c b/safeclib/mem_primitives_lib.c index cc189e5..285ae91 100644 --- a/safeclib/mem_primitives_lib.c +++ b/safeclib/mem_primitives_lib.c @@ -108,21 +108,21 @@ mem_prim_set (void *dest, uint32_t len, uint8_t value) lcount -= 16; break; - case 15: *lp++ = value32; - case 14: *lp++ = value32; - case 13: *lp++ = value32; - case 12: *lp++ = value32; - case 11: *lp++ = value32; - case 10: *lp++ = value32; - case 9: *lp++ = value32; - case 8: *lp++ = value32; - - case 7: *lp++ = value32; - case 6: *lp++ = value32; - case 5: *lp++ = value32; - case 4: *lp++ = value32; - case 3: *lp++ = value32; - case 2: *lp++ = value32; + case 15: *lp++ = value32; /* Fallthrough */ + case 14: *lp++ = value32; /* Fallthrough */ + case 13: *lp++ = value32; /* Fallthrough */ + case 12: *lp++ = value32; /* Fallthrough */ + case 11: *lp++ = value32; /* Fallthrough */ + case 10: *lp++ = value32; /* Fallthrough */ + case 9: *lp++ = value32; /* Fallthrough */ + case 8: *lp++ = value32; /* Fallthrough */ + + case 7: *lp++ = value32; /* Fallthrough */ + case 6: *lp++ = value32; /* Fallthrough */ + case 5: *lp++ = value32; /* Fallthrough */ + case 4: *lp++ = value32; /* Fallthrough */ + case 3: *lp++ = value32; /* Fallthrough */ + case 2: *lp++ = value32; /* Fallthrough */ case 1: *lp++ = value32; lcount = 0; break; @@ -194,21 +194,21 @@ mem_prim_set16 (uint16_t *dp, uint32_t len, uint16_t value) len -= 16; break; - case 15: *dp++ = value; - case 14: *dp++ = value; - case 13: *dp++ = value; - case 12: *dp++ = value; - case 11: *dp++ = value; - case 10: *dp++ = value; - case 9: *dp++ = value; - case 8: *dp++ = value; - - case 7: *dp++ = value; - case 6: *dp++ = value; - case 5: *dp++ = value; - case 4: *dp++ = value; - case 3: *dp++ = value; - case 2: *dp++ = value; + case 15: *dp++ = value; /* Fallthrough */ + case 14: *dp++ = value; /* Fallthrough */ + case 13: *dp++ = value; /* Fallthrough */ + case 12: *dp++ = value; /* Fallthrough */ + case 11: *dp++ = value; /* Fallthrough */ + case 10: *dp++ = value; /* Fallthrough */ + case 9: *dp++ = value; /* Fallthrough */ + case 8: *dp++ = value; /* Fallthrough */ + + case 7: *dp++ = value; /* Fallthrough */ + case 6: *dp++ = value; /* Fallthrough */ + case 5: *dp++ = value; /* Fallthrough */ + case 4: *dp++ = value; /* Fallthrough */ + case 3: *dp++ = value; /* Fallthrough */ + case 2: *dp++ = value; /* Fallthrough */ case 1: *dp++ = value; len = 0; break; @@ -265,21 +265,21 @@ mem_prim_set32 (uint32_t *dp, uint32_t len, uint32_t value) len -= 16; break; - case 15: *dp++ = value; - case 14: *dp++ = value; - case 13: *dp++ = value; - case 12: *dp++ = value; - case 11: *dp++ = value; - case 10: *dp++ = value; - case 9: *dp++ = value; - case 8: *dp++ = value; - - case 7: *dp++ = value; - case 6: *dp++ = value; - case 5: *dp++ = value; - case 4: *dp++ = value; - case 3: *dp++ = value; - case 2: *dp++ = value; + case 15: *dp++ = value; /* Fallthrough */ + case 14: *dp++ = value; /* Fallthrough */ + case 13: *dp++ = value; /* Fallthrough */ + case 12: *dp++ = value; /* Fallthrough */ + case 11: *dp++ = value; /* Fallthrough */ + case 10: *dp++ = value; /* Fallthrough */ + case 9: *dp++ = value; /* Fallthrough */ + case 8: *dp++ = value; /* Fallthrough */ + + case 7: *dp++ = value; /* Fallthrough */ + case 6: *dp++ = value; /* Fallthrough */ + case 5: *dp++ = value; /* Fallthrough */ + case 4: *dp++ = value; /* Fallthrough */ + case 3: *dp++ = value; /* Fallthrough */ + case 2: *dp++ = value; /* Fallthrough */ case 1: *dp++ = value; len = 0; break; @@ -518,21 +518,21 @@ mem_prim_move8 (uint8_t *dp, const uint8_t *sp, uint32_t len) len -= 16; break; - case 15: *dp++ = *sp++; - case 14: *dp++ = *sp++; - case 13: *dp++ = *sp++; - case 12: *dp++ = *sp++; - case 11: *dp++ = *sp++; - case 10: *dp++ = *sp++; - case 9: *dp++ = *sp++; - case 8: *dp++ = *sp++; - - case 7: *dp++ = *sp++; - case 6: *dp++ = *sp++; - case 5: *dp++ = *sp++; - case 4: *dp++ = *sp++; - case 3: *dp++ = *sp++; - case 2: *dp++ = *sp++; + case 15: *dp++ = *sp++; /* Fallthrough */ + case 14: *dp++ = *sp++; /* Fallthrough */ + case 13: *dp++ = *sp++; /* Fallthrough */ + case 12: *dp++ = *sp++; /* Fallthrough */ + case 11: *dp++ = *sp++; /* Fallthrough */ + case 10: *dp++ = *sp++; /* Fallthrough */ + case 9: *dp++ = *sp++; /* Fallthrough */ + case 8: *dp++ = *sp++; /* Fallthrough */ + + case 7: *dp++ = *sp++; /* Fallthrough */ + case 6: *dp++ = *sp++; /* Fallthrough */ + case 5: *dp++ = *sp++; /* Fallthrough */ + case 4: *dp++ = *sp++; /* Fallthrough */ + case 3: *dp++ = *sp++; /* Fallthrough */ + case 2: *dp++ = *sp++; /* Fallthrough */ case 1: *dp++ = *sp++; len = 0; break; @@ -568,21 +568,21 @@ mem_prim_move8 (uint8_t *dp, const uint8_t *sp, uint32_t len) len -= 16; break; - case 15: *--dp = *--sp; - case 14: *--dp = *--sp; - case 13: *--dp = *--sp; - case 12: *--dp = *--sp; - case 11: *--dp = *--sp; - case 10: *--dp = *--sp; - case 9: *--dp = *--sp; - case 8: *--dp = *--sp; - - case 7: *--dp = *--sp; - case 6: *--dp = *--sp; - case 5: *--dp = *--sp; - case 4: *--dp = *--sp; - case 3: *--dp = *--sp; - case 2: *--dp = *--sp; + case 15: *--dp = *--sp; /* Fallthrough */ + case 14: *--dp = *--sp; /* Fallthrough */ + case 13: *--dp = *--sp; /* Fallthrough */ + case 12: *--dp = *--sp; /* Fallthrough */ + case 11: *--dp = *--sp; /* Fallthrough */ + case 10: *--dp = *--sp; /* Fallthrough */ + case 9: *--dp = *--sp; /* Fallthrough */ + case 8: *--dp = *--sp; /* Fallthrough */ + + case 7: *--dp = *--sp; /* Fallthrough */ + case 6: *--dp = *--sp; /* Fallthrough */ + case 5: *--dp = *--sp; /* Fallthrough */ + case 4: *--dp = *--sp; /* Fallthrough */ + case 3: *--dp = *--sp; /* Fallthrough */ + case 2: *--dp = *--sp; /* Fallthrough */ case 1: *--dp = *--sp; len = 0; break; @@ -649,21 +649,21 @@ mem_prim_move16 (uint16_t *dp, const uint16_t *sp, uint32_t len) len -= 16; break; - case 15: *dp++ = *sp++; - case 14: *dp++ = *sp++; - case 13: *dp++ = *sp++; - case 12: *dp++ = *sp++; - case 11: *dp++ = *sp++; - case 10: *dp++ = *sp++; - case 9: *dp++ = *sp++; - case 8: *dp++ = *sp++; - - case 7: *dp++ = *sp++; - case 6: *dp++ = *sp++; - case 5: *dp++ = *sp++; - case 4: *dp++ = *sp++; - case 3: *dp++ = *sp++; - case 2: *dp++ = *sp++; + case 15: *dp++ = *sp++; /* Fallthrough */ + case 14: *dp++ = *sp++; /* Fallthrough */ + case 13: *dp++ = *sp++; /* Fallthrough */ + case 12: *dp++ = *sp++; /* Fallthrough */ + case 11: *dp++ = *sp++; /* Fallthrough */ + case 10: *dp++ = *sp++; /* Fallthrough */ + case 9: *dp++ = *sp++; /* Fallthrough */ + case 8: *dp++ = *sp++; /* Fallthrough */ + + case 7: *dp++ = *sp++; /* Fallthrough */ + case 6: *dp++ = *sp++; /* Fallthrough */ + case 5: *dp++ = *sp++; /* Fallthrough */ + case 4: *dp++ = *sp++; /* Fallthrough */ + case 3: *dp++ = *sp++; /* Fallthrough */ + case 2: *dp++ = *sp++; /* Fallthrough */ case 1: *dp++ = *sp++; len = 0; break; @@ -698,21 +698,21 @@ mem_prim_move16 (uint16_t *dp, const uint16_t *sp, uint32_t len) len -= 16; break; - case 15: *--dp = *--sp; - case 14: *--dp = *--sp; - case 13: *--dp = *--sp; - case 12: *--dp = *--sp; - case 11: *--dp = *--sp; - case 10: *--dp = *--sp; - case 9: *--dp = *--sp; - case 8: *--dp = *--sp; - - case 7: *--dp = *--sp; - case 6: *--dp = *--sp; - case 5: *--dp = *--sp; - case 4: *--dp = *--sp; - case 3: *--dp = *--sp; - case 2: *--dp = *--sp; + case 15: *--dp = *--sp; /* Fallthrough */ + case 14: *--dp = *--sp; /* Fallthrough */ + case 13: *--dp = *--sp; /* Fallthrough */ + case 12: *--dp = *--sp; /* Fallthrough */ + case 11: *--dp = *--sp; /* Fallthrough */ + case 10: *--dp = *--sp; /* Fallthrough */ + case 9: *--dp = *--sp; /* Fallthrough */ + case 8: *--dp = *--sp; /* Fallthrough */ + + case 7: *--dp = *--sp; /* Fallthrough */ + case 6: *--dp = *--sp; /* Fallthrough */ + case 5: *--dp = *--sp; /* Fallthrough */ + case 4: *--dp = *--sp; /* Fallthrough */ + case 3: *--dp = *--sp; /* Fallthrough */ + case 2: *--dp = *--sp; /* Fallthrough */ case 1: *--dp = *--sp; len = 0; break; @@ -779,21 +779,21 @@ mem_prim_move32 (uint32_t *dp, const uint32_t *sp, uint32_t len) len -= 16; break; - case 15: *dp++ = *sp++; - case 14: *dp++ = *sp++; - case 13: *dp++ = *sp++; - case 12: *dp++ = *sp++; - case 11: *dp++ = *sp++; - case 10: *dp++ = *sp++; - case 9: *dp++ = *sp++; - case 8: *dp++ = *sp++; - - case 7: *dp++ = *sp++; - case 6: *dp++ = *sp++; - case 5: *dp++ = *sp++; - case 4: *dp++ = *sp++; - case 3: *dp++ = *sp++; - case 2: *dp++ = *sp++; + case 15: *dp++ = *sp++; /* Fallthrough */ + case 14: *dp++ = *sp++; /* Fallthrough */ + case 13: *dp++ = *sp++; /* Fallthrough */ + case 12: *dp++ = *sp++; /* Fallthrough */ + case 11: *dp++ = *sp++; /* Fallthrough */ + case 10: *dp++ = *sp++; /* Fallthrough */ + case 9: *dp++ = *sp++; /* Fallthrough */ + case 8: *dp++ = *sp++; /* Fallthrough */ + + case 7: *dp++ = *sp++; /* Fallthrough */ + case 6: *dp++ = *sp++; /* Fallthrough */ + case 5: *dp++ = *sp++; /* Fallthrough */ + case 4: *dp++ = *sp++; /* Fallthrough */ + case 3: *dp++ = *sp++; /* Fallthrough */ + case 2: *dp++ = *sp++; /* Fallthrough */ case 1: *dp++ = *sp++; len = 0; break; @@ -827,21 +827,21 @@ mem_prim_move32 (uint32_t *dp, const uint32_t *sp, uint32_t len) len -= 16; break; - case 15: *--dp = *--sp; - case 14: *--dp = *--sp; - case 13: *--dp = *--sp; - case 12: *--dp = *--sp; - case 11: *--dp = *--sp; - case 10: *--dp = *--sp; - case 9: *--dp = *--sp; - case 8: *--dp = *--sp; - - case 7: *--dp = *--sp; - case 6: *--dp = *--sp; - case 5: *--dp = *--sp; - case 4: *--dp = *--sp; - case 3: *--dp = *--sp; - case 2: *--dp = *--sp; + case 15: *--dp = *--sp; /* Fallthrough */ + case 14: *--dp = *--sp; /* Fallthrough */ + case 13: *--dp = *--sp; /* Fallthrough */ + case 12: *--dp = *--sp; /* Fallthrough */ + case 11: *--dp = *--sp; /* Fallthrough */ + case 10: *--dp = *--sp; /* Fallthrough */ + case 9: *--dp = *--sp; /* Fallthrough */ + case 8: *--dp = *--sp; /* Fallthrough */ + + case 7: *--dp = *--sp; /* Fallthrough */ + case 6: *--dp = *--sp; /* Fallthrough */ + case 5: *--dp = *--sp; /* Fallthrough */ + case 4: *--dp = *--sp; /* Fallthrough */ + case 3: *--dp = *--sp; /* Fallthrough */ + case 2: *--dp = *--sp; /* Fallthrough */ case 1: *--dp = *--sp; len = 0; break; diff --git a/safeclib/safe_str_constraint.h b/safeclib/safe_str_constraint.h index a1fba3e..134401e 100644 --- a/safeclib/safe_str_constraint.h +++ b/safeclib/safe_str_constraint.h @@ -54,6 +54,7 @@ static inline void handle_error(char *orig_dest, rsize_t orig_dmax, /* null string to eliminate partial copy */ while (orig_dmax) { *orig_dest = '\0'; orig_dmax--; orig_dest++; } #else + orig_dmax = orig_dmax; *orig_dest = '\0'; #endif @@ -68,6 +69,7 @@ static inline void handle_wc_error(wchar_t *orig_dest, rsize_t orig_dmax, /* null string to eliminate partial copy */ while (orig_dmax) { *orig_dest = L'\0'; orig_dmax--; orig_dest++; } #else + orig_dmax = orig_dmax; *orig_dest = L'\0'; #endif diff --git a/safeclib/safeclib_private.h b/safeclib/safeclib_private.h index 7280e87..cc4f160 100644 --- a/safeclib/safeclib_private.h +++ b/safeclib/safeclib_private.h @@ -32,6 +32,12 @@ #ifndef __SAFECLIB_PRIVATE_H__ #define __SAFECLIB_PRIVATE_H__ +#ifdef __GNUC__ +#define _UNUSED __attribute__((__unused__)) +#else +#define _UNUSED +#endif /* __GNUC__ */ + #ifdef __KERNEL__ /* linux kernel environment */ @@ -51,6 +57,9 @@ #if HAVE_CONFIG_H #include "config.h" +#else +#include +#include #endif #include diff --git a/safeclib/snprintf_support.c b/safeclib/snprintf_support.c index 52a0739..a632a9c 100644 --- a/safeclib/snprintf_support.c +++ b/safeclib/snprintf_support.c @@ -55,7 +55,7 @@ #define CHK_FORMAT(X,Y) (((X)==(Y))?1:0) -unsigned int +static unsigned int parse_format(const char *format, char pformatList[], unsigned int maxFormats) { unsigned int numFormats = 0; @@ -202,7 +202,7 @@ parse_format(const char *format, char pformatList[], unsigned int maxFormats) return numFormats; } -unsigned int +static unsigned int check_integer_format(const char format) { unsigned int retValue = 0; // default failure diff --git a/safeclib/stpcpy_s.c b/safeclib/stpcpy_s.c index e15908f..c30b78c 100644 --- a/safeclib/stpcpy_s.c +++ b/safeclib/stpcpy_s.c @@ -46,10 +46,14 @@ * DESCRIPTION * The stpcpy_s function copies the string pointed to by src * (including the terminating null character) into the array +#ifdef SAFECLIB_STR_NULL_SLACK * pointed to by dest. All elements following the terminating * null character (if any) written by stpcpy_s in the array * of dmax characters pointed to by dest are nulled when * strcpy_s returns. The function returns a pointer to the +#else + * pointed to by dest. The function returns a pointer to the +#endif // SAFECLIB_STR_NULL_SLACK * end of the string in dest - that is to the null terminator * of dest - upon return. If an error occurs, NULL is returned * and err is set to the error encountered. @@ -88,7 +92,12 @@ * Copying shall not take place between objects that overlap. * If there is a runtime-constraint violation, then if dest * is not a null pointer and destmax is greater than zero and +#ifdef SAFECLIB_STR_NULL_SLACK * not greater than RSIZE_MAX_STR, then stpcpy_s nulls dest. +#else + * not greater than RSIZE_MAX_STR, then stpcpy_s stores a 0 + * terminator in dest. +#endif // SAFECLIB_STR_NULL_SLACK * * RETURN VALUE * a char pointer to the terminating null at the end of dest @@ -148,7 +157,9 @@ stpcpy_s(char *dest, rsize_t dmax, const char *src, errno_t *err) if (*dest == '\0') { #ifdef SAFECLIB_STR_NULL_SLACK /* null slack to clear any data */ - while (dmax) { *dest = '\0'; dmax--; dest++; } + char *filler = dest; + + while (dmax) { *filler = '\0'; dmax--; filler++; } #endif *err = RCNEGATE(EOK); return dest; @@ -182,7 +193,9 @@ stpcpy_s(char *dest, rsize_t dmax, const char *src, errno_t *err) if (*dest == '\0') { #ifdef SAFECLIB_STR_NULL_SLACK /* null slack to clear any data */ - while (dmax) { *dest = '\0'; dmax--; dest++; } + char *filler = dest; + + while (dmax) { *filler = '\0'; dmax--; filler++; } #endif *err = RCNEGATE(EOK); return dest; @@ -210,7 +223,9 @@ stpcpy_s(char *dest, rsize_t dmax, const char *src, errno_t *err) if (*dest == '\0') { #ifdef SAFECLIB_STR_NULL_SLACK /* null slack to clear any data */ - while (dmax) { *dest = '\0'; dmax--; dest++; } + char *filler = dest; + + while (dmax) { *filler = '\0'; dmax--; filler++; } #endif *err = RCNEGATE(EOK); return dest; diff --git a/safeclib/stpncpy_s.c b/safeclib/stpncpy_s.c index 890002d..a52b9d2 100644 --- a/safeclib/stpncpy_s.c +++ b/safeclib/stpncpy_s.c @@ -47,8 +47,10 @@ * The stpncpy_s function copies at most smax characters from the string * pointed to by src, including the terminating null byte ('\0'), to the * array pointed to by dest. Exactly smax characters are written at dest. +#ifdef SAFECLIB_STR_NULL_SLACK * If the length strlen_s(src) is smaller than smax, the remaining smax * characters in the array pointed to by dest are filled with null bytes. +#endif // SAFECLIB_STR_NULL_SLACK * If the length strlen_s(src) is greater than or equal to smax, the string * pointed to by dest will contain smax characters from src plus a null * characters (dest will be null-terminated). @@ -97,8 +99,13 @@ * If src and dest overlap, copying shall be stopped; destruction of src may have occurred. * If there is a runtime-constraint violation, then: * if dest is not a null pointer and dmax is greater than zero and +#ifdef SAFECLIB_STR_NULL_SLACK * not greater than RSIZE_MAX_STR, then stpncpy_s shall fill dest with nulls, * if library was compiled with SAFECLIB_STR_NULL_SLACK. +#else + * not greater than RSIZE_MAX_STR, then stpncpy_s shall write a terminator + * to the dest buffer. +#endif // SAFECLIB_STR_NULL_SLACK * * RETURN VALUE * a char pointer to the terminating null at the end of dest @@ -178,7 +185,7 @@ stpncpy_s(char *dest, rsize_t dmax, const char *src, rsize_t smax, errno_t *err) #ifdef SAFECLIB_STR_NULL_SLACK /* dmwheel1: Add check to prevent destruction of overlap into destination */ - if ((src < dest) && ((src+dmax) >= dest)) { + if ((src < dest) && ((src + smax) > dest)) { invoke_safe_str_constraint_handler("stpncpy_s: src+dmax overlaps into dest", NULL, ESOVRLP); *err = RCNEGATE(ESOVRLP); @@ -186,7 +193,7 @@ stpncpy_s(char *dest, rsize_t dmax, const char *src, rsize_t smax, errno_t *err) } /* dmwheel1: Add check to prevent destruction of overlap into source */ - if ((dest < src) && ((dest+dmax) >= src)) { + if ((dest < src) && ((dest + dmax) > src)) { invoke_safe_str_constraint_handler("stpncpy_s: dest+dmax overlaps into src", NULL, ESOVRLP); *err = RCNEGATE(ESOVRLP); diff --git a/safeclib/strcat_s.c b/safeclib/strcat_s.c index 16db8a7..2eaaf64 100644 --- a/safeclib/strcat_s.c +++ b/safeclib/strcat_s.c @@ -62,8 +62,10 @@ * INPUT PARAMETERS * dest pointer to string that will be extended by src * if dmax allows. The string is null terminated. +#ifdef SAFECLIB_STR_NULL_SLACK * If the resulting concatenated string is less * than dmax, the remaining slack space is nulled. +#endif // SAFECLIB_STR_NULL_SLACK * * dmax restricted maximum length of the resulting dest, * including the null @@ -82,7 +84,12 @@ * Copying shall not takeplace between objects that overlap * If there is a runtime-constraint violation, then if dest is * not a null pointer and dmax is greater than zero and not +#ifdef SAFECLIB_STR_NULL_SLACK * greater than RSIZE_MAX_STR, then strcat_s nulls dest. +#else + * greater than RSIZE_MAX_STR, then strcat_s writes a terminator + * to dest. +#endif // SAFECLIB_STR_NULL_SLACK * * RETURN VALUE * EOK successful operation, all the characters from src diff --git a/safeclib/strcpy_s.c b/safeclib/strcpy_s.c index 67f6f03..874c4c3 100644 --- a/safeclib/strcpy_s.c +++ b/safeclib/strcpy_s.c @@ -46,10 +46,14 @@ * DESCRIPTION * The strcpy_s function copies the string pointed to by src * (including the terminating null character) into the array +#ifdef SAFECLIB_STR_NULL_SLACK * pointed to by dest. All elements following the terminating * null character (if any) written by strcpy_s in the array * of dmax characters pointed to by dest are nulled when * strcpy_s returns. +#else + * pointed to by dest. +#endif // SAFECLIB_STR_NULL_SLACK * * SPECIFIED IN * ISO/IEC TR 24731, Programming languages, environments @@ -75,7 +79,12 @@ * Copying shall not take place between objects that overlap. * If there is a runtime-constraint violation, then if dest * is not a null pointer and destmax is greater than zero and +#ifdef SAFECLIB_STR_NULL_SLACK * not greater than RSIZE_MAX_STR, then strcpy_s nulls dest. +#else + * not greater than RSIZE_MAX_STR, then strcpy_s writes a + * terminator to dest. +#endif // SAFECLIB_STR_NULL_SLACK * * RETURN VALUE * EOK successful operation, the characters in src were diff --git a/safeclib/strncpy_s.c b/safeclib/strncpy_s.c index 1fcdf6f..bc9d286 100644 --- a/safeclib/strncpy_s.c +++ b/safeclib/strncpy_s.c @@ -48,10 +48,12 @@ * (characters that follow a null character are not copied) from the * array pointed to by src to the array pointed to by dest. If no null * character was copied from src, then dest[n] is set to a null character. +#ifdef SAFECLIB_STR_NULL_SLACK * * All elements following the terminating null character (if any) * written by strncpy_s in the array of dmax characters pointed to * by dest take on the null value when strncpy_s returns. +#endif // SAFECLIB_STR_NULL_SLACK * * Specicified in: * ISO/IEC TR 24731-1, Programming languages, environments @@ -82,7 +84,11 @@ * Copying shall not take place between objects that overlap. * If there is a runtime-constraint violation, then if dest * is not a null pointer and dmax greater than RSIZE_MAX_STR, +#ifdef SAFECLIB_STR_NULL_SLACK * then strncpy_s nulls dest. +#else + * the strncpy_s writes a terminator to dest. +#endif // SAFECLIB_STR_NULL_SLACK * * RETURN VALUE * EOK successful operation, the characters in src were copied diff --git a/safeclib/wcpcpy_s.c b/safeclib/wcpcpy_s.c index d388dc6..aea6555 100644 --- a/safeclib/wcpcpy_s.c +++ b/safeclib/wcpcpy_s.c @@ -47,10 +47,14 @@ * The wcpcpy_s function copies the wide character string pointed * to by src (including the terminating null character) into the * array pointed to by dest, and returns a pointer to the end of +#ifdef SAFECLIB_STR_NULL_SLACK * the wide character string. All elements following the terminating * null character (if any) written by wcpcpy_s in the array of * dmax characters pointed to by dest are nulled when * wcpcpy_s returns. +#else + * the wide character string. +#endif // SAFECLIB_STR_NULL_SLACK * * SPECIFIED IN * ISO/IEC TR 24731, Programming languages, environments @@ -86,7 +90,12 @@ * Copying shall not take place between objects that overlap. * If there is a runtime-constraint violation, then if dest * is not a null pointer and destmax is greater than zero and +#ifdef SAFECLIB_STR_NULL_SLACK * not greater than RSIZE_MAX_STR, then strcpy_s nulls dest. +#else + * not greater than RSIZE_MAX_STR, then strcpy_s stores a + * terminator at dest. +#endif // SAFECLIB_STR_NULL_SLACK * * RETURN VALUE * a wchar_t pointer to the terminating null at the end of dest @@ -169,7 +178,9 @@ wcpcpy_s(wchar_t* dest, rsize_t dmax, const wchar_t* src, errno_t *err) if (*dest == L'\0') { #ifdef SAFECLIB_STR_NULL_SLACK /* null slack to clear any data */ - while (dmax) { *dest = L'\0'; dmax--; dest++; } + wchar_t *filler = dest; + + while (dmax) { *filler = L'\0'; dmax--; filler++; } #endif *err = RCNEGATE(EOK); return dest; /* successful return */ @@ -195,7 +206,9 @@ wcpcpy_s(wchar_t* dest, rsize_t dmax, const wchar_t* src, errno_t *err) if (*dest == L'\0') { #ifdef SAFECLIB_STR_NULL_SLACK /* null slack to clear any data */ - while (dmax) { *dest = L'\0'; dmax--; dest++; } + wchar_t *filler = dest; + + while (dmax) { *filler = L'\0'; dmax--; filler++; } #endif *err = RCNEGATE(EOK); return dest; /* successful return */ diff --git a/safeclib/wcscat_s.c b/safeclib/wcscat_s.c index 19363df..c1102b1 100644 --- a/safeclib/wcscat_s.c +++ b/safeclib/wcscat_s.c @@ -48,11 +48,13 @@ * to by src (including the terminating null character) to the * end of the string pointed to by dest. The initial wide character * from src overwrites the null character at the end of dest. +#ifdef SAFECLIB_STR_NULL_SLACK * * All elements following the terminating null character (if * any) written by strcat_s in the array of dmax characters * pointed to by dest take unspecified values when strcat_s * returns. +#endif // SAFECLIB_STR_NULL_SLACK * * SPECIFIED IN * ISO/IEC TR 24731, Programming languages, environments @@ -82,7 +84,12 @@ * Copying shall not takeplace between objects that overlap * If there is a runtime-constraint violation, then if dest is * not a null pointer and dmax is greater than zero and not +#ifdef SAFECLIB_STR_NULL_SLACK * greater than RSIZE_MAX_STR, then strcat_s nulls dest. +#else + * greater than RSIZE_MAX_STR, then strcat_s stores a + * terminator at dest. +#endif // SAFECLIB_STR_NULL_SLACK * * RETURN VALUE * EOK successful operation, all the characters from src diff --git a/safeclib/wcscpy_s.c b/safeclib/wcscpy_s.c index 64aad61..e620c33 100644 --- a/safeclib/wcscpy_s.c +++ b/safeclib/wcscpy_s.c @@ -46,10 +46,14 @@ * DESCRIPTION * The wcscpy_s function copies the wide character string pointed * to by src (including the terminating null character) into the +#ifdef SAFECLIB_STR_NULL_SLACK * array pointed to by dest. All elements following the terminating * null character (if any) written by strcpy_s in the array of * dmax characters pointed to by dest are nulled when * wcscpy_s returns. +#else + * array pointed to by dest. +#endif // SAFECLIB_STR_NULL_SLACK * * SPECIFIED IN * ISO/IEC TR 24731, Programming languages, environments @@ -75,7 +79,12 @@ * Copying shall not take place between objects that overlap. * If there is a runtime-constraint violation, then if dest * is not a null pointer and destmax is greater than zero and +#ifdef SAFECLIB_STR_NULL_SLACK * not greater than RSIZE_MAX_STR, then strcpy_s nulls dest. +#else + * not greater than RSIZE_MAX_STR, then strcpy_s stores a + * terminator at dest. +#endif // SAFECLIB_STR_NULL_SLACK * * RETURN VALUE * EOK successful operation, the characters in src were diff --git a/safeclib/wcsncpy_s.c b/safeclib/wcsncpy_s.c index 67ddda1..cfa2d7b 100644 --- a/safeclib/wcsncpy_s.c +++ b/safeclib/wcsncpy_s.c @@ -48,6 +48,7 @@ * (characters that follow a null character are not copied) from the * array pointed to by src to the array pointed to by dest. If no null * character was copied from src, then dest[slen] is set to a null character. +#ifdef SAFECLIB_STR_NULL_SLACK * * All elements following the terminating null character (if any) * written by wcsncpy_s in the array of dmax characters pointed to @@ -60,6 +61,7 @@ * array is used multiple times to string manipulation routines in this * library. If this extra security is not required, ensure that the * library is compiled without #DEFINE SAFECLIB_STR_NULL_SLACK. +#endif // SAFECLIB_STR_NULL_SLACK * * Specicified in: * ISO/IEC TR 24731-1, Programming languages, environments @@ -90,7 +92,11 @@ * Copying shall not take place between objects that overlap. * If there is a runtime-constraint violation, then if dest * is not a null pointer and dmax greater than RSIZE_MAX_STR, +#ifdef SAFECLIB_STR_NULL_SLACK * then strncpy_s nulls dest. +#else + * then strncpy_s stores a terminator at dest. +#endif // SAFECLIB_STR_NULL_SLACK * * RETURN VALUE * EOK successful operation, the characters in src were copied diff --git a/unittests/Safe_String_UnitTestMain.c b/unittests/Safe_String_UnitTestMain.c index fa40511..e40f0cc 100644 --- a/unittests/Safe_String_UnitTestMain.c +++ b/unittests/Safe_String_UnitTestMain.c @@ -12,72 +12,9 @@ #include #include #include +#include "test_private.h" -extern int test_memcmp_s(); -extern int test_memcmp16_s(); -extern int test_memcmp32_s(); -extern int test_memcpy_s(); -extern int test_memcpy16_s(); -extern int test_memcpy32_s(); -extern int test_memmove_s(); -extern int test_memmove16_s(); -extern int test_memmove32_s(); -extern int test_memset_s(); -extern int test_memset16_s(); -extern int test_memset32_s(); -extern int test_memzero_s(); -extern int test_memzero16_s(); -extern int test_memzero32_s(); -extern int test_strcasecmp_s(); -extern int test_strcasestr_s(); -extern int test_strcat_s(); -extern int test_strcmp_s(); -extern int test_strcmpfld_s(); -extern int test_strcpy_s(); -extern int test_strcpyfld_s(); -extern int test_strcpyfldin_s(); -extern int test_strcpyfldout_s(); -extern int test_strcspn_s (); -extern int test_strfirstchar_s(); -extern int test_strfirstdiff_s(); -extern int test_strfirstsame_s(); -extern int test_strisalphanumeric_s(); -extern int test_strisascii_s(); -extern int test_strisdigit_s(); -extern int test_strishex_s(); -extern int test_strislowercase_s(); -extern int test_strismixed_s(); -extern int test_strispassword_s(); -extern int test_strisuppercase_s(); -extern int test_strlastchar_s(); -extern int test_strlastdiff_s(); -extern int test_strlastsame_s(); -extern int test_strljustify_s(); -extern int test_strncat_s (); -extern int test_strncpy_s (); -extern int test_strnlen_s (); -extern int test_strnterminate_s(); -extern int test_strpbrk_s (); -extern int test_strprefix_s(); -extern int test_strremovews_s(); -extern int test_strspn_s (); -extern int test_strstr_s (); -extern int test_strtok_s(); -extern int test_strtolowercase_s(); -extern int test_strtouppercase_s(); -extern int test_strzero_s(); -extern int test_stpncpy_s(); -extern int test_stpcpy_s(); -extern int test_wcpcpy_s(); -extern int test_wcscat_s(); -extern int test_wcscpy_s(); -extern int test_wcsncat_s(); -extern int test_wcsncpy_s (void); -extern int test_wcsnlen_s (void); -extern int test_wmemcpy_s(void); -extern int test_wmemmove_s(void); -extern int test_wmemset_s(void); -extern int test_wmemcmp_s(void); +#define TEST_FUNC(f) { #f, f } int main(void) { @@ -86,105 +23,122 @@ int main(void) { rsize_t dmax = 128; rsize_t smax = 21; errno_t err; + static const struct { + const char * const name; + int (*func)(void); + } funcs[] = { + TEST_FUNC(test_memcmp_s), + TEST_FUNC(test_memcmp16_s), + TEST_FUNC(test_memcmp32_s), + TEST_FUNC(test_memcpy_s), + TEST_FUNC(test_memcpy16_s), + TEST_FUNC(test_memcpy32_s), + TEST_FUNC(test_memmove_s), + TEST_FUNC(test_memmove16_s), + TEST_FUNC(test_memmove32_s), + TEST_FUNC(test_memset_s), + TEST_FUNC(test_memset16_s), + TEST_FUNC(test_memset32_s), + TEST_FUNC(test_memzero_s), + TEST_FUNC(test_memzero16_s), + TEST_FUNC(test_memzero32_s), + TEST_FUNC(test_stpcpy_s), + TEST_FUNC(test_stpncpy_s), + TEST_FUNC(test_strcasecmp_s), + TEST_FUNC(test_strcasestr_s), + TEST_FUNC(test_strcat_s), + TEST_FUNC(test_strcmp_s), + TEST_FUNC(test_strcmpfld_s), + TEST_FUNC(test_strcpy_s), + TEST_FUNC(test_strcpyfld_s), + TEST_FUNC(test_strcpyfldin_s), + TEST_FUNC(test_strcpyfldout_s), + TEST_FUNC(test_strcspn_s), + TEST_FUNC(test_strfirstchar_s), + TEST_FUNC(test_strfirstdiff_s), + TEST_FUNC(test_strfirstsame_s), + TEST_FUNC(test_strisalphanumeric_s), + TEST_FUNC(test_strisascii_s), + TEST_FUNC(test_strisdigit_s), + TEST_FUNC(test_strishex_s), + TEST_FUNC(test_strislowercase_s), + TEST_FUNC(test_strismixed_s), + TEST_FUNC(test_strispassword_s), + TEST_FUNC(test_strisuppercase_s), + TEST_FUNC(test_strlastchar_s), + TEST_FUNC(test_strlastdiff_s), + TEST_FUNC(test_strlastsame_s), + TEST_FUNC(test_strljustify_s), + TEST_FUNC(test_strncat_s), + TEST_FUNC(test_strncpy_s), + TEST_FUNC(test_strnlen_s), + TEST_FUNC(test_strnterminate_s), + TEST_FUNC(test_strpbrk_s), + TEST_FUNC(test_strprefix_s), + TEST_FUNC(test_strremovews_s), + TEST_FUNC(test_strspn_s), + TEST_FUNC(test_strstr_s), + TEST_FUNC(test_strtok_s), + TEST_FUNC(test_strtolowercase_s), + TEST_FUNC(test_strtouppercase_s), + TEST_FUNC(test_strzero_s), + TEST_FUNC(test_wcpcpy_s), + TEST_FUNC(test_wcscat_s), + TEST_FUNC(test_wcscpy_s), + TEST_FUNC(test_wcsncat_s), + TEST_FUNC(test_wcsncpy_s), + TEST_FUNC(test_wcsnlen_s), + TEST_FUNC(test_wmemcpy_s), + TEST_FUNC(test_wmemmove_s), + TEST_FUNC(test_wmemset_s), + TEST_FUNC(test_wmemcmp_s), + }; + unsigned int i; + int errs; puts("!!!Basic Test Suite for Safe String Operations!!!"); puts(" ERRORS PRINT TO CONSOLE"); puts("----------------BEGIN TEST--------------------"); - test_memcmp_s(); - test_memcmp16_s(); - test_memcmp32_s(); - test_memcpy_s(); - test_memcpy16_s(); - test_memcpy32_s(); - test_memmove_s(); - test_memmove16_s(); - test_memmove32_s(); - test_memset_s(); - test_memset16_s(); - test_memset32_s(); - test_memzero_s(); - test_memzero16_s(); - test_memzero32_s(); - - - test_stpcpy_s(); /* New - Done */ - test_stpncpy_s(); /* New - Done */ - - test_strcasecmp_s(); - test_strcasestr_s(); - test_strcat_s(); - test_strcmp_s(); - test_strcmpfld_s(); - test_strcpy_s(); - test_strcpyfld_s(); - test_strcpyfldin_s(); - test_strcpyfldout_s(); - test_strcspn_s (); - - test_strfirstchar_s(); - test_strfirstdiff_s(); - test_strfirstsame_s(); - test_strisalphanumeric_s(); - test_strisascii_s(); - test_strisdigit_s(); - test_strishex_s(); - test_strislowercase_s(); - test_strismixed_s(); - test_strispassword_s(); - test_strisuppercase_s(); - - test_strlastchar_s(); - test_strlastdiff_s(); - test_strlastsame_s(); - test_strljustify_s(); - - test_strncat_s (); - test_strncpy_s (); - test_strnlen_s (); - test_strnterminate_s(); - test_strpbrk_s (); - test_strprefix_s(); - test_strremovews_s(); - test_strspn_s (); - test_strstr_s (); - test_strtok_s(); - test_strtolowercase_s(); - test_strtouppercase_s(); - test_strzero_s(); - - test_wcpcpy_s(); /* New - Done */ - test_wcscat_s(); /* New - Done */ - test_wcscpy_s(); /* New - Done */ - test_wcsncat_s(); /* New - Done */ - test_wcsncpy_s(); /* New - Done */ - test_wcsnlen_s(); /* New - Done */ - test_wmemcpy_s(); /* New - Done */ - test_wmemmove_s(); /* New - Done */ - test_wmemset_s(); /* New - Done */ - test_wmemcmp_s(); /* New - Done */ + for (i = 0; i < sizeof(funcs) / sizeof(funcs[0]); ++i) { + printf("test %d = %s\n", i, funcs[i].name); + errs = funcs[i].func(); + if (errs) { + printf("%d error(s) found, test halted\n", errs); + return 1; + } + } char str[] = "This is a char array"; char str2[] = "...And another one."; int indicator = -1; strcpy_s(dest, dmax, str); - char *ret = stpcpy_s(&dest[20], 108, str2, &err); + stpcpy_s(&dest[20], 108, str2, &err); if (err != EOK) { puts("stpcpy_s returned failure"); + ++errs; } int val = 55; if ( (err = snprintf_s_si(src, 128, "Test sprintf_s_si() with simple format string [%s] and %d", dest, val)) < 0 ) { if ( SNPRFNEGATE(ESBADFMT) == err ) { puts("snprintf_s_si returned failure: Error Bad Format String."); + ++errs; } else if ( SNPRFNEGATE(ESFMTTYP) == err ) { puts("snprintf_s_si returned failure: Error Bad Argument Type for format string."); + ++errs; } else { printf("snprintf_s_si failed with unknown error: %d\n", err); + ++errs; } } else if ((strcmp_s(src, smax, "Test sprintf_s_si() with simple format string [This is a char array...And another one.] and 55", &indicator) != EOK ) || (indicator != 0 )) { puts("snprintf_s_si() failed - output was:"); puts(src); + ++errs; + } + if (errs) { + printf("%d error(s) found, test halted\n", errs); + return 1; } puts("----------------END TEST--------------------"); return EXIT_SUCCESS; diff --git a/unittests/test_memcmp16_s.c b/unittests/test_memcmp16_s.c index d4ed057..81b9f83 100644 --- a/unittests/test_memcmp16_s.c +++ b/unittests/test_memcmp16_s.c @@ -9,10 +9,10 @@ #define LEN ( 128 ) -int test_memcmp16_s() +int test_memcmp16_s(void) { errno_t rc; - + int errs = 0; uint32_t len; int32_t ind; int32_t std_ind; @@ -25,56 +25,63 @@ int test_memcmp16_s() rc = memcmp16_s(NULL, LEN, mem2, LEN, &ind); if (rc != ESNULLP) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp16_s(mem1, LEN, NULL, LEN, &ind); if (rc != ESNULLP) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp16_s(mem1, LEN, mem2, LEN, NULL); if (rc != ESNULLP) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp16_s(mem1, 0, mem2, LEN, &ind); if (rc != ESZEROL) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp16_s(mem1, LEN, mem2, 0, &ind); if (rc != ESZEROL) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp16_s(mem1, RSIZE_MAX_MEM+1, mem2, LEN, &ind); if (rc != ESLEMAX) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp16_s(mem1, LEN, mem2, RSIZE_MAX_MEM+1, &ind); if (rc != ESLEMAX) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -85,19 +92,22 @@ int test_memcmp16_s() len = 1; rc = memcmp16_s(mem1, len, mem2, len, &ind); if (rc != EOK) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } if (ind != 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } std_ind = memcmp(mem1, mem2, len*2); if (ind != std_ind) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -108,19 +118,22 @@ int test_memcmp16_s() len = 2; rc = memcmp16_s(mem1, len, mem2, len, &ind); if (rc != EOK) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } if (ind != 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } std_ind = memcmp(mem1, mem2, len*2); if (ind != std_ind) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -130,19 +143,22 @@ int test_memcmp16_s() rc = memcmp16_s(mem1, LEN, mem2, LEN, &ind); if (rc != EOK) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } if (ind != 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } std_ind = memcmp(mem1, mem2, LEN*2); if (ind != std_ind) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -154,23 +170,26 @@ int test_memcmp16_s() rc = memcmp16_s(mem1, LEN, mem2, LEN, &ind); if (rc != EOK) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } if (ind == 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } std_ind = memcmp(mem1, mem2, LEN*2); if (ind != std_ind) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_memcmp32_s.c b/unittests/test_memcmp32_s.c index 4913e31..d6251e7 100644 --- a/unittests/test_memcmp32_s.c +++ b/unittests/test_memcmp32_s.c @@ -9,12 +9,13 @@ #define LEN ( 128 ) -int test_memcmp32_s() +int test_memcmp32_s(void) { errno_t rc; + int errs = 0; uint32_t len; int32_t ind; - int32_t std_ind; + int std_ind; uint32_t i; uint32_t mem1[LEN]; @@ -24,56 +25,63 @@ int test_memcmp32_s() rc = memcmp32_s(NULL, LEN, mem2, LEN, &ind); if (rc != ESNULLP) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp32_s(mem1, LEN, NULL, LEN, &ind); if (rc != ESNULLP) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp32_s(mem1, LEN, mem2, LEN, NULL); if (rc != ESNULLP) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp32_s(mem1, 0, mem2, LEN, &ind); if (rc != ESZEROL) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp32_s(mem1, LEN, mem2, 0, &ind); if (rc != ESZEROL) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp32_s(mem1, RSIZE_MAX_MEM+1, mem2, LEN, &ind); if (rc != ESLEMAX) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp32_s(mem1, LEN, mem2, RSIZE_MAX_MEM+1, &ind); if (rc != ESLEMAX) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -84,19 +92,22 @@ int test_memcmp32_s() len = 1; rc = memcmp32_s(mem1, len, mem2, len, &ind); if (rc != EOK) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } if (ind != 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } std_ind = memcmp(mem1, mem2, len*4); - if (ind != 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + if (std_ind != 0) { + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, std_ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -107,19 +118,22 @@ int test_memcmp32_s() len = 2; rc = memcmp32_s(mem1, len, mem2, len, &ind); if (rc != EOK) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } if (ind != 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } std_ind = memcmp(mem1, mem2, len*4); - if (ind != 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + if (std_ind != 0) { + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, std_ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -129,19 +143,22 @@ int test_memcmp32_s() rc = memcmp32_s(mem1, LEN, mem2, LEN, &ind); if (rc != EOK) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } if (ind != 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } ind = memcmp(mem1, mem2, LEN*4); if (ind != 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -153,17 +170,19 @@ int test_memcmp32_s() rc = memcmp32_s(mem1, LEN, mem2, LEN, &ind); if (rc != EOK) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } if (ind == 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc ); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_memcmp_s.c b/unittests/test_memcmp_s.c index fb9bdb5..65e4505 100644 --- a/unittests/test_memcmp_s.c +++ b/unittests/test_memcmp_s.c @@ -16,6 +16,7 @@ static uint8_t mem2[LEN]; int test_memcmp_s (void) { errno_t rc; + int errs = 0; int32_t ind; int32_t std_ind; uint32_t len; @@ -24,56 +25,63 @@ int test_memcmp_s (void) rc = memcmp_s(NULL, LEN, mem2, LEN, &ind); if (rc != ESNULLP) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp_s(mem1, LEN, NULL, LEN, &ind); if (rc != ESNULLP) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp_s(mem1, LEN, mem2, LEN, NULL); if (rc != ESNULLP) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp_s(mem1, 0, mem2, LEN, &ind); if (rc != ESZEROL) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp_s(mem1, LEN, mem2, 0, &ind); if (rc != ESZEROL) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp_s(mem1, LEN, mem2, RSIZE_MAX_MEM+1, &ind); if (rc != ESLEMAX) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcmp_s(mem1, RSIZE_MAX_MEM+1, mem2, LEN, &ind); if (rc != ESLEMAX) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -85,19 +93,22 @@ int test_memcmp_s (void) rc = memcmp_s(mem1, len, mem2, len, &ind); if (rc != EOK) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } if (ind != 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } std_ind = memcmp(mem1, mem2, len); if (ind != std_ind) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -109,19 +120,22 @@ int test_memcmp_s (void) rc = memcmp_s(&mem1[1], len, &mem2[1], len, &ind); if (rc != EOK) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } if (ind != 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } std_ind = memcmp(mem1, mem2, len); if (ind != std_ind) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -133,19 +147,22 @@ int test_memcmp_s (void) rc = memcmp_s(mem1, len, mem2, len, &ind); if (rc != EOK) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } if (ind != 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } std_ind = memcmp(mem1, mem2, len); if (ind != std_ind) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -158,13 +175,15 @@ int test_memcmp_s (void) rc = memcmp_s(mem1, len, mem2, len, &ind); if (rc != EOK) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } if (ind < 1) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -177,13 +196,15 @@ int test_memcmp_s (void) rc = memcmp_s(mem1, len, mem2, len, &ind); if (rc != EOK) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } if (ind > -1) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -195,17 +216,19 @@ int test_memcmp_s (void) rc = memcmp_s(mem1, len, mem2, len, &ind); if (rc != EOK) { - debug_printf("%s %u Ind=%d Error rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d Error rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } if (ind != 0) { - debug_printf("%s %u Ind=%d rc=%u \n", - __FUNCTION__, __LINE__, ind, rc); + printf("%s %u Ind=%d rc=%u \n", + __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_memcpy16_s.c b/unittests/test_memcpy16_s.c index 0e5da19..24283a2 100644 --- a/unittests/test_memcpy16_s.c +++ b/unittests/test_memcpy16_s.c @@ -11,9 +11,10 @@ #define LEN ( 1024 ) -int test_memcpy16_s() +int test_memcpy16_s(void) { errno_t rc; + int errs = 0; uint32_t len; uint32_t i; @@ -24,48 +25,54 @@ int test_memcpy16_s() rc = memcpy16_s(NULL, LEN, mem2, LEN); if (rc != ESNULLP) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcpy16_s(mem1, 0, mem2, LEN); if (rc != ESZEROL) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcpy16_s(mem1, RSIZE_MAX_MEM16+1, mem2, LEN); if (rc != ESLEMAX) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcpy16_s(mem1, LEN, NULL, LEN); if (rc != ESNULLP) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcpy16_s(mem1, 10, mem2, 0); if (rc != ESZEROL) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ rc = memcpy16_s(mem1, LEN, mem2, RSIZE_MAX_MEM16+1); if (rc != ESLEMAX) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -76,14 +83,16 @@ int test_memcpy16_s() len = 1; rc = memcpy16_s(mem1, len, mem2, len); if (rc != EOK) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } for (i=0; i #include @@ -58,4 +59,70 @@ #define debug_printf(...) #endif +int test_memcmp_s(void); +int test_memcmp16_s(void); +int test_memcmp32_s(void); +int test_memcpy_s(void); +int test_memcpy16_s(void); +int test_memcpy32_s(void); +int test_memmove_s(void); +int test_memmove16_s(void); +int test_memmove32_s(void); +int test_memset_s(void); +int test_memset16_s(void); +int test_memset32_s(void); +int test_memzero_s(void); +int test_memzero16_s(void); +int test_memzero32_s(void); +int test_strcasecmp_s(void); +int test_strcasestr_s(void); +int test_strcat_s(void); +int test_strcmp_s(void); +int test_strcmpfld_s(void); +int test_strcpy_s(void); +int test_strcpyfld_s(void); +int test_strcpyfldin_s(void); +int test_strcpyfldout_s(void); +int test_strcspn_s(void); +int test_strfirstchar_s(void); +int test_strfirstdiff_s(void); +int test_strfirstsame_s(void); +int test_strisalphanumeric_s(void); +int test_strisascii_s(void); +int test_strisdigit_s(void); +int test_strishex_s(void); +int test_strislowercase_s(void); +int test_strismixed_s(void); +int test_strispassword_s(void); +int test_strisuppercase_s(void); +int test_strlastchar_s(void); +int test_strlastdiff_s(void); +int test_strlastsame_s(void); +int test_strljustify_s(void); +int test_strncat_s(void); +int test_strncpy_s(void); +int test_strnlen_s(void); +int test_strnterminate_s(void); +int test_strpbrk_s(void); +int test_strprefix_s(void); +int test_strremovews_s(void); +int test_strspn_s(void); +int test_strstr_s(void); +int test_strtok_s(void); +int test_strtolowercase_s(void); +int test_strtouppercase_s(void); +int test_strzero_s(void); +int test_stpncpy_s(void); +int test_stpcpy_s(void); +int test_wcpcpy_s(void); +int test_wcscat_s(void); +int test_wcscpy_s(void); +int test_wcsncat_s(void); +int test_wcsncpy_s(void); +int test_wcsnlen_s(void); +int test_wmemcpy_s(void); +int test_wmemmove_s(void); +int test_wmemset_s(void); +int test_wmemcmp_s(void); + #endif /* __TEST_PRIVATE_H__ */ diff --git a/unittests/test_stpcpy_s.c b/unittests/test_stpcpy_s.c index a2afa42..1bb9ca0 100644 --- a/unittests/test_stpcpy_s.c +++ b/unittests/test_stpcpy_s.c @@ -81,6 +81,7 @@ static char str2[LEN]; int test_stpcpy_s (void) { char *ret; + int errs = 0; errno_t rc; #ifdef SAFE_LIB_STR_NULL_SLACK uint32_t i; @@ -97,11 +98,13 @@ int test_stpcpy_s (void) if (rc != ESNULLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -112,10 +115,12 @@ int test_stpcpy_s (void) if (rc != ESZEROL) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } @@ -127,10 +132,12 @@ int test_stpcpy_s (void) if (rc != ESLEMAX) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -143,11 +150,13 @@ int test_stpcpy_s (void) if (rc != ESNULLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK @@ -155,12 +164,14 @@ int test_stpcpy_s (void) if (str1[i] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[0] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -175,12 +186,14 @@ int test_stpcpy_s (void) if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } @@ -194,11 +207,13 @@ int test_stpcpy_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str1+strnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -213,10 +228,12 @@ int test_stpcpy_s (void) if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK @@ -224,12 +241,14 @@ int test_stpcpy_s (void) if (str1[i] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[0] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -246,10 +265,12 @@ int test_stpcpy_s (void) if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK @@ -257,12 +278,14 @@ int test_stpcpy_s (void) if (str1[i] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[5] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -285,10 +308,12 @@ int test_stpcpy_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str1) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK @@ -296,12 +321,14 @@ int test_stpcpy_s (void) if (str1[i] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[0] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -317,15 +344,18 @@ int test_stpcpy_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str2) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (*str2 != '\0') { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -339,6 +369,7 @@ int test_stpcpy_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /* be sure the results are the same as strcmp */ @@ -346,11 +377,13 @@ int test_stpcpy_s (void) if (ind != 0) { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str1+strnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -364,11 +397,13 @@ int test_stpcpy_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str1+strnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /* be sure the results are the same as strcmp */ @@ -376,6 +411,7 @@ int test_stpcpy_s (void) if (ind != 0) { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -389,15 +425,18 @@ int test_stpcpy_s (void) if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (*str1 != '\0') { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -411,15 +450,18 @@ int test_stpcpy_s (void) if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (*str2 != '\0') { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -433,6 +475,7 @@ int test_stpcpy_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /* be sure the results are the same as strcmp */ @@ -440,10 +483,12 @@ int test_stpcpy_s (void) if (ind != 0) { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str1+strnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -457,10 +502,12 @@ int test_stpcpy_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str2+strnlen_s(str2, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /* be sure the results are the same as strcpy */ @@ -468,11 +515,12 @@ int test_stpcpy_s (void) if (ind != 0) { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_stpncpy_s.c b/unittests/test_stpncpy_s.c index f8d288a..29ce345 100644 --- a/unittests/test_stpncpy_s.c +++ b/unittests/test_stpncpy_s.c @@ -88,6 +88,7 @@ extern char *stpncpy_s(char *dest, rsize_t dmax, const char *src, rsize_t smax, int test_stpncpy_s (void) { + int errs = 0; char *ret; errno_t rc; uint32_t i; @@ -105,11 +106,13 @@ printf("Test #%d:\n", ++testno); if (rc != ESNULLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -120,10 +123,12 @@ printf("Test #%d:\n", ++testno); if (rc != ESZEROL) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } @@ -135,10 +140,12 @@ printf("Test #%d:\n", ++testno); if (rc != ESLEMAX) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -151,11 +158,13 @@ printf("Test #%d:\n", ++testno); if (rc != ESNULLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK @@ -163,12 +172,14 @@ printf("Test #%d:\n", ++testno); if (str1[i] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[0] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -184,12 +195,14 @@ printf("Test #%d:\n", ++testno); if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } @@ -204,11 +217,13 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str1+strnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -223,10 +238,12 @@ printf("Test #%d:\n", ++testno); if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK @@ -234,12 +251,14 @@ printf("Test #%d:\n", ++testno); if (str1[i] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[0] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -256,10 +275,12 @@ printf("Test #%d:\n", ++testno); if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK @@ -267,12 +288,14 @@ printf("Test #%d:\n", ++testno); if (str1[i] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[5] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -295,10 +318,12 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str1) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK @@ -306,12 +331,14 @@ printf("Test #%d:\n", ++testno); if (str1[i] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[0] != '\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -327,15 +354,18 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str2) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (*str2 != '\0') { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -351,6 +381,7 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /* be sure the results are the same as strcmp */ @@ -358,11 +389,13 @@ printf("Test #%d:\n", ++testno); if (ind != 0) { printf("%s %u -%s- <> -%s- (smax=%zu) Error rc=%u \n", __FUNCTION__, __LINE__, str1, str2, sz, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str1+strnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -376,11 +409,13 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str1+strnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } else { /* be sure the results are the same as strcmp */ @@ -389,12 +424,19 @@ printf("Test #%d:\n", ++testno); if (ind != 0 || sz != 3) { printf("%s %u -%s- <> -%s- (smax=%zu) Error rc=%u \n", __FUNCTION__, __LINE__, str1, str2, sz, rc ); + ++errs; } /* be sure that the slack is correct */ for (i=1; i<6; i++) { - if (ret[i] != 'x') { +#ifdef SAFECLIB_STR_NULL_SLACK + const char slack = '\0'; +#else + const char slack = 'x'; +#endif // SAFECLIB_STR_NULL_SLACK + if (ret[i] != slack) { printf("%s %u Incorrect Slack at returned ptr index %d Error rc=%u \n", __FUNCTION__, __LINE__, i, rc ); + ++errs; } } } @@ -410,11 +452,13 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str1+strnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } else { /* be sure the results are the same as strcmp */ @@ -422,19 +466,27 @@ printf("Test #%d:\n", ++testno); if (ind != 0) { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } else { /* be sure that the nulls are correct */ for (i=0; i<5; i++) { if (ret[i] != '\0') { printf("%s %u Incorrect NULL fill at returned ptr index %d Error rc=%u \n", __FUNCTION__, __LINE__, i, rc ); + ++errs; } } /* be sure that the slack is correct */ for (; i<15; i++) { - if (ret[i] != 'x') { +#ifdef SAFECLIB_STR_NULL_SLACK + const char slack = '\0'; +#else + const char slack = 'x'; +#endif // SAFECLIB_STR_NULL_SLACK + if (ret[i] != slack) { printf("%s %u Incorrect Slack at returned ptr index %d Error rc=%u \n", __FUNCTION__, __LINE__, i, rc ); + ++errs; } } } @@ -451,11 +503,13 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str1+strnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } else { /* be sure the results are the same as strcmp */ @@ -463,12 +517,19 @@ printf("Test #%d:\n", ++testno); if (ind != 0) { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } else { /* be sure that the slack is correct */ for (i=1; i<5; i++) { - if (ret[i] != 'x') { +#ifdef SAFECLIB_STR_NULL_SLACK + const char slack = '\0'; +#else + const char slack = 'x'; +#endif // SAFECLIB_STR_NULL_SLACK + if (ret[i] != slack) { printf("%s %u Incorrect Slack at returned ptr index %d Error rc=%u \n", __FUNCTION__, __LINE__, i, rc ); + ++errs; } } } @@ -485,11 +546,13 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str1+strnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } else { /* be sure the results are the same as strcmp */ @@ -497,12 +560,19 @@ printf("Test #%d:\n", ++testno); if (ind != 0) { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } else { /* be sure that the slack is correct */ for (i=1; i<5; i++) { - if (ret[i] != 'x') { +#ifdef SAFECLIB_STR_NULL_SLACK + const char slack = '\0'; +#else + const char slack = 'x'; +#endif // SAFECLIB_STR_NULL_SLACK + if (ret[i] != slack) { printf("%s %u Incorrect Slack at returned ptr index %d Error rc=%u \n", __FUNCTION__, __LINE__, i, rc ); + ++errs; } } } @@ -520,15 +590,18 @@ printf("Test #%d:\n", ++testno); if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (*str1 != '\0') { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -543,15 +616,18 @@ printf("Test #%d:\n", ++testno); if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (*str1 != '\0') { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -566,6 +642,7 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /* be sure the results are the same as strcmp */ @@ -573,10 +650,12 @@ printf("Test #%d:\n", ++testno); if (ind != 0) { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str1+strnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -590,10 +669,12 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != '\0' || ret != str1+strnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /* be sure the results are the same as strcpy */ @@ -601,10 +682,11 @@ printf("Test #%d:\n", ++testno); if (ind != 0) { printf("%s %u -%s- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_strcasecmp_s.c b/unittests/test_strcasecmp_s.c index c54892f..001e3bd 100644 --- a/unittests/test_strcasecmp_s.c +++ b/unittests/test_strcasecmp_s.c @@ -17,6 +17,7 @@ static char str2[LEN]; int test_strcasecmp_s (void) { errno_t rc; + int errs = 0; int ind; int std_ind; @@ -27,11 +28,13 @@ int test_strcasecmp_s (void) if (rc != ESNULLP) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -40,11 +43,13 @@ int test_strcasecmp_s (void) if (rc != ESNULLP) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -53,6 +58,7 @@ int test_strcasecmp_s (void) if (rc != ESNULLP) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -61,11 +67,13 @@ int test_strcasecmp_s (void) if (rc != ESZEROL) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -74,11 +82,13 @@ int test_strcasecmp_s (void) if (rc != ESLEMAX) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -90,17 +100,20 @@ int test_strcasecmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } std_ind = strcasecmp(str1, str2); if (ind != std_ind) { printf("%s %u ind=%d std_ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, std_ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -112,11 +125,13 @@ int test_strcasecmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -127,11 +142,13 @@ int test_strcasecmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -143,11 +160,13 @@ int test_strcasecmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -159,17 +178,20 @@ int test_strcasecmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } std_ind = strcasecmp(str1, str2); if (ind != std_ind) { printf("%s %u ind=%d std_ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, std_ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -181,11 +203,13 @@ int test_strcasecmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -196,11 +220,13 @@ int test_strcasecmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -212,11 +238,13 @@ int test_strcasecmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != ('I' - 'E')) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -228,15 +256,17 @@ int test_strcasecmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != ('1' - 'I')) { printf("%s %u Error ind=%d rc=%d %d \n", __FUNCTION__, __LINE__, ind, rc, ('1' - 'I')); + ++errs; } /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_strcasestr_s.c b/unittests/test_strcasestr_s.c index 6e9eb5b..9ac64ea 100644 --- a/unittests/test_strcasestr_s.c +++ b/unittests/test_strcasestr_s.c @@ -13,8 +13,9 @@ extern errno_t strcasestr_s (char *dest, rsize_t dmax, const char *src, rsize_t slen, char **substring); -int test_strcasestr_s() +int test_strcasestr_s(void) { + int errs = 0; errno_t rc; char *sub; char *std_sub; @@ -32,11 +33,13 @@ int test_strcasestr_s() if (rc != ESNULLP) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -45,11 +48,13 @@ int test_strcasestr_s() if (rc != ESNULLP) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -58,6 +63,7 @@ int test_strcasestr_s() if (rc != ESNULLP) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -66,11 +72,13 @@ int test_strcasestr_s() if (rc != ESZEROL) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -79,11 +87,13 @@ int test_strcasestr_s() if (rc != ESLEMAX) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -92,11 +102,13 @@ int test_strcasestr_s() if (rc != ESZEROL) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -105,11 +117,13 @@ int test_strcasestr_s() if (rc != ESLEMAX) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -121,22 +135,25 @@ int test_strcasestr_s() if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != str1) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /* compare to legacy */ std_sub = strcasestr(str1, str2); - if ((int)sub != (int)std_sub) { // comparison to handle 32-bit library return and 64-bit library return + if (sub != std_sub) { printf("%s %u Error strcasestr_s() does not have same return as strcasestr() when str1 & str2 are zero length strings. rc=%u \n", __FUNCTION__, __LINE__, rc); printf("str1:[%s]\n", str1); printf("str2:[%s]\n", str2); printf("strcasestr_s returns:[%p]\n", sub); printf("strcasestr returns:[%p]\n\n", std_sub); + ++errs; } /*--------------------------------------------------*/ @@ -148,22 +165,25 @@ int test_strcasestr_s() if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != str1) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /* compare to legacy */ std_sub = strcasestr(str1, str2); - if ((int)sub != (int)std_sub) { // comparison to handle 32-bit library return and 64-bit library return + if (sub != std_sub) { printf("%s %u Error strcasestr_s() does not have same return value as strcasestr() when str2 is zero length string. rc=%u \n", __FUNCTION__, __LINE__, rc); printf("str1:[%s]\n", str1); printf("str2:[%s]\n", str2); printf("strcasestr_s returns:[%p]\n", sub); printf("strcasestr returns:[%p]\n\n", std_sub); + ++errs; } /*--------------------------------------------------*/ @@ -176,22 +196,25 @@ int test_strcasestr_s() if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != str1) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /* compare to legacy */ std_sub = strcasestr(str1, str2); - if ((int)sub != (int)std_sub) { // comparison to handle 32-bit library return and 64-bit library return + if (sub != std_sub) { printf("%s %u Error strcasestr_s() does not have same return value as strcasestr() when str2 is zero length string. rc=%u \n", __FUNCTION__, __LINE__, rc); printf("str1:[%s]\n", str1); printf("str2:[%s]\n", str2); printf("strcasestr_s returns:[%p]\n", sub); printf("strcasestr returns:[%p]\n\n", std_sub); + ++errs; } /*--------------------------------------------------*/ @@ -204,11 +227,13 @@ int test_strcasestr_s() if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != &str1[0]) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -221,11 +246,13 @@ int test_strcasestr_s() if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != &str1[1]) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -238,11 +265,13 @@ int test_strcasestr_s() if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != &str1[15]) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -258,22 +287,25 @@ int test_strcasestr_s() if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != &str1[18]) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /* compare to legacy */ std_sub = strcasestr(str1, str2); - if ((int)sub != (int)std_sub) { // comparison to handle 32-bit library return and 64-bit library return + if (sub != std_sub) { printf("%s %u Error strcasestr_s() does not have same return value as strcasestr() when str2 is substring of the end of str1. rc=%u \n", __FUNCTION__, __LINE__, rc); printf("str1:[%s]\n", str1); printf("str2:[%s]\n", str2); printf("strcasestr_s returns:[%p]\n", sub); printf("strcasestr returns:[%p]\n\n", std_sub); + ++errs; } /*--------------------------------------------------*/ @@ -289,22 +321,25 @@ int test_strcasestr_s() if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != &str1[18]) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /* compare to legacy */ std_sub = strcasestr(str1, str2); - if ((int)sub != (int)std_sub) { // comparison to handle 32-bit library return and 64-bit library return + if (sub != std_sub) { printf("%s %u Error strcasestr_s() does not have same return value as strcasestr() when str2 is substring of middle of str1. rc=%u \n", __FUNCTION__, __LINE__, rc); printf("str1:[%s]\n", str1); printf("str2:[%s]\n", str2); printf("strcasestr_s returns:[%p]\n", sub); printf("strcasestr returns:[%p]\n\n", std_sub); + ++errs; } /*--------------------------------------------------*/ @@ -316,11 +351,13 @@ int test_strcasestr_s() if (rc != ESNOTFND) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != NULL) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -332,11 +369,13 @@ int test_strcasestr_s() if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != &str1[5]) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -348,11 +387,13 @@ int test_strcasestr_s() if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != &str1[5]) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -364,11 +405,13 @@ int test_strcasestr_s() if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != &str1[5]) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -381,11 +424,13 @@ int test_strcasestr_s() if (rc != ESNOTFND) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != NULL) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -397,11 +442,13 @@ int test_strcasestr_s() if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != &str1[5]) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -414,21 +461,24 @@ int test_strcasestr_s() if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (sub != &str1[1]) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /* compare to legacy */ std_sub = strcasestr(str1, str2); - if ((int)sub != (int)std_sub) { // comparison to handle 32-bit library return and 64-bit library return + if (sub != std_sub) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_strcat_s.c b/unittests/test_strcat_s.c index 2e6f700..614c26a 100644 --- a/unittests/test_strcat_s.c +++ b/unittests/test_strcat_s.c @@ -16,6 +16,7 @@ static char str2[LEN]; int test_strcat_s (void) { errno_t rc; + int errs = 0; int32_t ind; int32_t len1; int32_t len2; @@ -25,32 +26,36 @@ int test_strcat_s (void) rc = strcat_s(NULL, LEN, str2); if (rc != ESNULLP) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ rc = strcat_s(str1, LEN, NULL); if (rc != ESNULLP) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ rc = strcat_s(str1, 0, str2); if (rc != ESZEROL) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ rc = strcat_s(str1, (RSIZE_MAX_STR+1), str2); if (rc != ESLEMAX) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -61,13 +66,15 @@ int test_strcat_s (void) rc = strcat_s(str1, 1, str2); if (rc != ESUNTERM) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != '\0') { - debug_printf("%s %u Expected null \n", - __FUNCTION__, __LINE__); + printf("%s %u Expected null \n", + __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -77,13 +84,15 @@ int test_strcat_s (void) rc = strcat_s(str1, 2, str2); if (rc != ESUNTERM) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != '\0') { - debug_printf("%s %u Expected null \n", - __FUNCTION__, __LINE__); + printf("%s %u Expected null \n", + __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -96,14 +105,16 @@ int test_strcat_s (void) rc = strcat_s(str1, 50, str2); if (rc != EOK) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } len3 = strlen(str1); if (len3 != (len1+len2)) { - debug_printf("%s %u lengths wrong: %u %u %u \n", - __FUNCTION__, __LINE__, len1, len2, len3); + printf("%s %u lengths wrong: %u %u %u \n", + __FUNCTION__, __LINE__, len1, len2, len3); + ++errs; } /*--------------------------------------------------*/ @@ -114,13 +125,15 @@ int test_strcat_s (void) rc = strcat_s(str1, 1, str2); if (rc != ESNOSPC) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != '\0') { - debug_printf("%s %u Expected null \n", - __FUNCTION__, __LINE__); + printf("%s %u Expected null \n", + __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -130,13 +143,15 @@ int test_strcat_s (void) rc = strcat_s(str1, 2, str2); if (rc != ESNOSPC) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != '\0') { - debug_printf("%s %u Expected null \n", - __FUNCTION__, __LINE__); + printf("%s %u Expected null \n", + __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -146,14 +161,16 @@ int test_strcat_s (void) rc = strcat_s(str1, 20, str2); if (rc != EOK) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } ind = strcmp(str1, str2 ); if (ind != 0) { - debug_printf("%s %u Error -%s- \n", - __FUNCTION__, __LINE__, str1); + printf("%s %u Error -%s- \n", + __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -164,13 +181,15 @@ int test_strcat_s (void) rc = strcat_s(str1, LEN, str2); if (rc != EOK) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != '\0') { - debug_printf("%s %u Expected null \n", - __FUNCTION__, __LINE__); + printf("%s %u Expected null \n", + __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -180,14 +199,16 @@ int test_strcat_s (void) rc = strcat_s(str1, LEN, str2); if (rc != EOK) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } ind = strcmp(str1, str2); if (ind != 0) { - debug_printf("%s %u Error -%s- \n", - __FUNCTION__, __LINE__, str1); + printf("%s %u Error -%s- \n", + __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -197,14 +218,16 @@ int test_strcat_s (void) rc = strcat_s(str1, LEN, str2); if (rc != EOK) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } ind = strcmp(str1, "qqweqqkeep it simple"); if (ind != 0) { - debug_printf("%s %u Error -%s- \n", - __FUNCTION__, __LINE__, str1); + printf("%s %u Error -%s- \n", + __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -214,8 +237,9 @@ int test_strcat_s (void) rc = strcat_s(str1, 12, str2); if (rc != ESNOSPC) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -225,14 +249,16 @@ int test_strcat_s (void) rc = strcat_s(str1, 52, str2); if (rc != EOK) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } ind = strcmp(str1, "1234keep it simple"); if (ind != 0) { - debug_printf("%s %u Error -%s- \n", - __FUNCTION__, __LINE__, str1); + printf("%s %u Error -%s- \n", + __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -241,13 +267,15 @@ int test_strcat_s (void) rc = strcat_s(str1, 8, &str1[7]); if (rc != ESOVRLP) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != '\0') { - debug_printf("%s %u Expected null \n", - __FUNCTION__, __LINE__); + printf("%s %u Expected null \n", + __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -256,13 +284,15 @@ int test_strcat_s (void) rc = strcat_s(str1, 9, &str1[8]); if (rc != ESOVRLP) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != '\0') { - debug_printf("%s %u Expected null \n", - __FUNCTION__, __LINE__); + printf("%s %u Expected null \n", + __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -272,14 +302,16 @@ int test_strcat_s (void) rc = strcat_s(str2, 31, &str1[0]); if (rc != EOK) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } ind = strcmp(str2, "123keep it simple"); if (ind != 0) { - debug_printf("%s %u Error -%s- \n", - __FUNCTION__, __LINE__, str1); + printf("%s %u Error -%s- \n", + __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -289,19 +321,21 @@ int test_strcat_s (void) rc = strcat_s(str2, 10, str1); if (rc != EOK) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc); + ++errs; } ind = strcmp(str2, "123456789"); if (ind != 0) { - debug_printf("%s %u Error -%s- \n", - __FUNCTION__, __LINE__, str1); + printf("%s %u Error -%s- \n", + __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_strcmp_s.c b/unittests/test_strcmp_s.c index b15fff5..4920a6e 100644 --- a/unittests/test_strcmp_s.c +++ b/unittests/test_strcmp_s.c @@ -17,6 +17,7 @@ static char str2[LEN]; int test_strcmp_s (void) { errno_t rc; + int errs = 0; int ind; int std_ind; @@ -26,11 +27,13 @@ int test_strcmp_s (void) if (rc != ESNULLP) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -39,11 +42,13 @@ int test_strcmp_s (void) if (rc != ESNULLP) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -52,6 +57,7 @@ int test_strcmp_s (void) if (rc != ESNULLP) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -60,11 +66,13 @@ int test_strcmp_s (void) if (rc != ESZEROL) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -73,11 +81,13 @@ int test_strcmp_s (void) if (rc != ESLEMAX) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -89,17 +99,20 @@ int test_strcmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } std_ind = strcmp(str1, str2); if (ind != std_ind) { printf("%s %u ind=%d std_ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, std_ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -111,11 +124,13 @@ int test_strcmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -128,17 +143,20 @@ int test_strcmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != (-32)) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } std_ind = strcmp(str1, str2); if (ind != std_ind) { printf("%s %u ind=%d std_ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, std_ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -151,17 +169,20 @@ int test_strcmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 32) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } std_ind = strcmp(str1, str2); if (ind != std_ind) { printf("%s %u ind=%d std_ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, std_ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -172,11 +193,13 @@ int test_strcmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind != 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /* be sure the results are the same as strcmp */ @@ -184,6 +207,7 @@ int test_strcmp_s (void) if (ind != std_ind) { printf("%s %u ind=%d std_ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, std_ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -195,11 +219,13 @@ int test_strcmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind <= 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /* be sure the results are the same as strcmp */ @@ -207,6 +233,7 @@ int test_strcmp_s (void) if (ind != std_ind) { printf("%s %u ind=%d std_ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, std_ind, rc); + ++errs; } /*--------------------------------------------------*/ @@ -218,11 +245,13 @@ int test_strcmp_s (void) if (rc != EOK) { printf("%s %u Error rc=%d \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (ind >= 0) { printf("%s %u Error ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, rc); + ++errs; } /* be sure the results are the same as strcmp */ @@ -230,11 +259,12 @@ int test_strcmp_s (void) if (ind != std_ind) { printf("%s %u ind=%d std_ind=%d rc=%d \n", __FUNCTION__, __LINE__, ind, std_ind, rc); + ++errs; } /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_strcmpfld_s.c b/unittests/test_strcmpfld_s.c index 8a2d8d9..0a55b0e 100644 --- a/unittests/test_strcmpfld_s.c +++ b/unittests/test_strcmpfld_s.c @@ -11,9 +11,10 @@ #define MAX ( 128 ) #define LEN ( 128 ) -int test_strcmpfld_s() +int test_strcmpfld_s(void) { errno_t rc; + int errs = 0; uint32_t i; rsize_t len; int ind; @@ -26,8 +27,9 @@ int test_strcmpfld_s() rc = strcmpfld_s(NULL, LEN, str2, &ind); if (rc != ESNULLP) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc ); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -35,8 +37,9 @@ int test_strcmpfld_s() len = 5; rc = strcmpfld_s(str1, len, NULL, &ind); if (rc != ESNULLP) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc ); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -44,24 +47,27 @@ int test_strcmpfld_s() len = 5; rc = strcmpfld_s(str1, len, str2, NULL); if (rc != ESNULLP) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc ); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ rc = strcmpfld_s(str1, 0, str2, &ind); if (rc != ESZEROL) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc ); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ rc = strcmpfld_s(str1, (RSIZE_MAX_STR+1), str2, &ind); if (rc != ESLEMAX) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc ); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -73,14 +79,16 @@ int test_strcmpfld_s() len = 1; rc = strcmpfld_s(str1, len, str2, &ind); if (rc != EOK) { - debug_printf("%s %u Error rc=%u \n", - __FUNCTION__, __LINE__, rc ); + printf("%s %u Error rc=%u \n", + __FUNCTION__, __LINE__, rc ); + ++errs; } for (i=0; i -%ls- (smax=%lu) Error rc=%u \n", __FUNCTION__, __LINE__, str1, str2, sz, rc ); + ++errs; } if (ret == NULL || ret[0] != L'\0' || ret != str1+wcsnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -376,22 +409,26 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != L'\0' || ret != str1+wcsnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } sz = wcsnlen_s(str1, LEN); if (sz != 5) { printf("%s %u (sz=%lu <> 5) Error rc=%u \n", __FUNCTION__, __LINE__, sz, rc ); + ++errs; } rc = memcmp_s(str1, LEN, str2, (6)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u -%ls- <> -%ls- (size=%lu) Error rc=%u \n", __FUNCTION__, __LINE__, str1, str2, sz, rc ); + ++errs; } @@ -407,15 +444,18 @@ printf("Test #%d:\n", ++testno); if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (*str1 != L'\0') { printf("%s %u -%ls- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -430,15 +470,18 @@ printf("Test #%d:\n", ++testno); if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (*str2 != L'\0') { printf("%s %u -%ls- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -452,16 +495,19 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } rc = memcmp_s(str1, LEN, str2, (3)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u -%ls- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } if (ret == NULL || ret[0] != L'\0' || ret != str2+wcsnlen_s(str2, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -475,16 +521,19 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret == NULL || ret[0] != L'\0' || ret != str1+wcsnlen_s(str1, LEN) ) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } rc = memcmp_s(str1, LEN, str2, (3)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u -%ls- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } @@ -500,19 +549,22 @@ printf("Test #%d:\n", ++testno); if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (ret != NULL) { printf("Returned pointer incorrect: %s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (*str2 != L'\0') { printf("%s %u -%ls- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_wcscat_s.c b/unittests/test_wcscat_s.c index 689af75..e05bb22 100644 --- a/unittests/test_wcscat_s.c +++ b/unittests/test_wcscat_s.c @@ -44,6 +44,7 @@ extern errno_t wcscat_s(wchar_t* dest, rsize_t dmax, const wchar_t* src); int test_wcscat_s (void) { errno_t rc; + int errs = 0; int32_t ind; int32_t len1; int32_t len2; @@ -60,6 +61,7 @@ int test_wcscat_s (void) if (rc != ESNULLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -70,6 +72,7 @@ int test_wcscat_s (void) if (rc != ESNULLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -80,6 +83,7 @@ int test_wcscat_s (void) if (rc != ESZEROL) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -90,6 +94,7 @@ int test_wcscat_s (void) if (rc != ESLEMAX) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -103,11 +108,13 @@ int test_wcscat_s (void) if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != L'\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -121,11 +128,13 @@ int test_wcscat_s (void) if (rc != ESUNTERM) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != L'\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -139,11 +148,13 @@ int test_wcscat_s (void) if (rc != ESUNTERM) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != L'\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -157,11 +168,13 @@ int test_wcscat_s (void) if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != L'\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -178,12 +191,14 @@ int test_wcscat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } len3 = wcsnlen_s(str1, LEN); if (len3 != (len1+len2)) { printf("%s %u lengths wrong: %u %u %u \n", __FUNCTION__, __LINE__, len1, len2, len3); + ++errs; } /*--------------------------------------------------*/ @@ -198,11 +213,13 @@ int test_wcscat_s (void) if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != L'\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -216,11 +233,13 @@ int test_wcscat_s (void) if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != L'\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -234,12 +253,14 @@ int test_wcscat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } rc = memcmp_s(str1, LEN, str2, wcsnlen_s(str2, LEN)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- \n", __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -254,11 +275,13 @@ int test_wcscat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != L'\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -272,12 +295,14 @@ int test_wcscat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } rc = memcmp_s(str2, LEN, L"keep it simple", (15)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- \n", __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -291,12 +316,14 @@ int test_wcscat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } rc = memcmp_s(str1, LEN, L"qqweqqkeep it simple", (20)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- \n", __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -310,6 +337,7 @@ int test_wcscat_s (void) if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -323,12 +351,14 @@ int test_wcscat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } rc = memcmp_s(str2, LEN, L"keep it simple1234", (19)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- \n", __FUNCTION__, __LINE__, str1); + ++errs; } @@ -343,11 +373,13 @@ int test_wcscat_s (void) if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[13] != L'\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -361,12 +393,14 @@ int test_wcscat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } rc = memcmp_s(str2, LEN, L"123keep it simple", (17)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- \n", __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -380,6 +414,7 @@ int test_wcscat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } rc = memcmp_s(str2, LEN, L"123456789", (9)*sizeof(wchar_t), &ind ); @@ -387,6 +422,7 @@ int test_wcscat_s (void) if (ind != 0) { printf("%s %u Error -%ls- \n", __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -400,17 +436,19 @@ int test_wcscat_s (void) if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str2[0] != L'\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_wcscpy_s.c b/unittests/test_wcscpy_s.c index 294c168..90a627b 100644 --- a/unittests/test_wcscpy_s.c +++ b/unittests/test_wcscpy_s.c @@ -84,6 +84,7 @@ extern errno_t wcscpy_s(wchar_t* dest, rsize_t dmax, const wchar_t* src); int test_wcscpy_s (void) { errno_t rc; + int errs = 0; #ifdef SAFE_LIB_STR_NULL_SLACK uint32_t i; #endif /*SAFE_LIB_STR_NULL_SLACK*/ @@ -102,6 +103,7 @@ printf("Test #%d:\n", ++testno); if (rc != ESNULLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -112,6 +114,7 @@ printf("Test #%d:\n", ++testno); if (rc != ESZEROL) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -122,6 +125,7 @@ printf("Test #%d:\n", ++testno); if (rc != ESLEMAX) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -134,6 +138,7 @@ printf("Test #%d:\n", ++testno); if (rc != ESNULLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK @@ -141,12 +146,14 @@ printf("Test #%d:\n", ++testno); if (str1[i] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[0] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -161,6 +168,7 @@ printf("Test #%d:\n", ++testno); if (rc != ESLEMAX) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -173,6 +181,7 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -188,6 +197,7 @@ printf("Test #%d:\n", ++testno); if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK @@ -195,12 +205,14 @@ printf("Test #%d:\n", ++testno); if (str1[i] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[0] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -218,6 +230,7 @@ printf("Test #%d:\n", ++testno); if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK @@ -225,12 +238,14 @@ printf("Test #%d:\n", ++testno); if (str1[i] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[8] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -248,6 +263,7 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK @@ -255,12 +271,14 @@ printf("Test #%d:\n", ++testno); if (str1[i] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[0] != L'\0') { printf("%s %u Error - string should be NULL rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -277,12 +295,14 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } rc = memcmp_s(str2, LEN, str1, (sz+1)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- <> -%ls-\n", __FUNCTION__, __LINE__, str2, str1); + ++errs; } @@ -298,12 +318,14 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } rc = memcmp_s(str1, LEN, str2, (sz)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u -%ls- <> -%ls- (smax=%lu) Error rc=%u \n", __FUNCTION__, __LINE__, str1, str2, sz, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -318,17 +340,20 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } sz = wcsnlen_s(str1, LEN); if (sz != sz_orig && sz == 14) { printf("%s %u (sz=%lu <> 5) Error rc=%u \n", __FUNCTION__, __LINE__, sz, rc ); + ++errs; } rc = memcmp_s(str1, LEN, str2, (sz)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u -%ls- <> -%ls- (size=%lu) Error rc=%u \n", __FUNCTION__, __LINE__, str1, str2, sz, rc ); + ++errs; } @@ -344,11 +369,13 @@ printf("Test #%d:\n", ++testno); if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (*str1 != L'\0') { printf("%s %u -%ls- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -362,11 +389,13 @@ printf("Test #%d:\n", ++testno); if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (*str2 != L'\0') { printf("%s %u -%ls- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -381,12 +410,14 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } rc = memcmp_s(str1, LEN, str2, (3)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u -%ls- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -402,12 +433,14 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } rc = memcmp_s(str1, LEN, str2, (3)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u -%ls- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } @@ -424,14 +457,16 @@ printf("Test #%d:\n", ++testno); if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (*str2 != L'\0') { printf("%s %u -%ls- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_wcsncat_s.c b/unittests/test_wcsncat_s.c index 865ccf8..832a1d4 100644 --- a/unittests/test_wcsncat_s.c +++ b/unittests/test_wcsncat_s.c @@ -87,6 +87,7 @@ extern errno_t wcsncat_s (wchar_t *dest, rsize_t dmax, const wchar_t *src, rsize int test_wcsncat_s (void) { errno_t rc; + int errs = 0; int32_t ind; int32_t len1; int32_t len2; @@ -103,6 +104,7 @@ int test_wcsncat_s (void) if (rc != ESNULLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -113,6 +115,7 @@ int test_wcsncat_s (void) if (rc != ESNULLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -123,6 +126,7 @@ int test_wcsncat_s (void) if (rc != ESLEMAX) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ /* 4 Test zero maximum length of destination */ @@ -132,6 +136,7 @@ int test_wcsncat_s (void) if (rc != ESZEROL) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -142,6 +147,7 @@ int test_wcsncat_s (void) if (rc != ESLEMAX) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } @@ -156,11 +162,13 @@ int test_wcsncat_s (void) if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != '\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -173,11 +181,13 @@ int test_wcsncat_s (void) if (rc != ESUNTERM) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != '\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -191,11 +201,13 @@ int test_wcsncat_s (void) if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != '\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -212,18 +224,21 @@ int test_wcsncat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } len3 = wcsnlen_s(str1, LEN); if (len3 != (len1+len2)) { printf("%s %u lengths wrong: %u %u %u \n", __FUNCTION__, __LINE__, len1, len2, len3); + ++errs; } rc = memcmp_s(str1, LEN, L"aaaaaaaaaakeep it si", (len3+1)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- \n", __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -240,18 +255,21 @@ int test_wcsncat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } len3 = wcsnlen_s(str1, LEN); if (len3 != (len1+len2)) { printf("%s %u lengths wrong: %u %u %u \n", __FUNCTION__, __LINE__, len1, len2, len3); + ++errs; } rc = memcmp_s(str1, LEN, L"aaaaaaaaaakeep it simple", (len3+1)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- \n", __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -266,11 +284,13 @@ int test_wcsncat_s (void) if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != '\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -284,11 +304,13 @@ int test_wcsncat_s (void) if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != '\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -302,12 +324,14 @@ int test_wcsncat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } rc = memcmp_s(str1, LEN, str2, wcsnlen_s(str2, LEN)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- \n", __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -322,11 +346,13 @@ int test_wcsncat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[0] != '\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -340,12 +366,14 @@ int test_wcsncat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } rc = memcmp_s(str2, LEN, L"keep it simple", (15)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- \n", __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -359,12 +387,14 @@ int test_wcsncat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } rc = memcmp_s(str2, LEN, L"qqweqqkeep it simple", (20)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- \n", __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -378,11 +408,13 @@ int test_wcsncat_s (void) if (rc != ESUNTERM) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str2[0] != '\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -396,11 +428,13 @@ int test_wcsncat_s (void) if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str2[0] != '\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -413,11 +447,13 @@ int test_wcsncat_s (void) if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str1[7] != '\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ @@ -431,12 +467,14 @@ int test_wcsncat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } rc = memcmp_s(str2, LEN, L"keep it simple1234", (19)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- \n", __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -450,12 +488,14 @@ int test_wcsncat_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } rc = memcmp_s(str2, LEN, L"123456789keep it", (17)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- \n", __FUNCTION__, __LINE__, str1); + ++errs; } /*--------------------------------------------------*/ @@ -469,17 +509,19 @@ int test_wcsncat_s (void) if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } if (str2[0] != L'\0') { printf("%s %u Expected null \n", __FUNCTION__, __LINE__); + ++errs; } /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_wcsncpy_s.c b/unittests/test_wcsncpy_s.c index 009f47a..3a86ffa 100644 --- a/unittests/test_wcsncpy_s.c +++ b/unittests/test_wcsncpy_s.c @@ -84,6 +84,7 @@ extern errno_t wmemset_s (wchar_t *dest, wchar_t value, rsize_t len); int test_wcsncpy_s (void) { errno_t rc; + int errs = 0; #ifdef SAFE_LIB_STR_NULL_SLACK uint32_t i; #endif /*SAFE_LIB_STR_NULL_SLACK*/ @@ -102,6 +103,7 @@ printf("Test #%d:\n", ++testno); if (rc != ESNULLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -112,6 +114,7 @@ printf("Test #%d:\n", ++testno); if (rc != ESZEROL) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -122,6 +125,7 @@ printf("Test #%d:\n", ++testno); if (rc != ESLEMAX) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -134,6 +138,7 @@ printf("Test #%d:\n", ++testno); if (rc != ESNULLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK @@ -141,12 +146,14 @@ printf("Test #%d:\n", ++testno); if (str1[i] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[0] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -158,18 +165,21 @@ printf("Test #%d:\n", ++testno); if (rc != ESZEROL) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK for (i=0; i -%ls-\n", __FUNCTION__, __LINE__, str1, str2); + ++errs; } @@ -284,17 +306,20 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (str1[sz] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } rc = memcmp_s(str1, LEN, str2, (sz+1)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- <> -%ls-\n", __FUNCTION__, __LINE__, str1, str2); + ++errs; } /*--------------------------------------------------*/ @@ -310,18 +335,21 @@ printf("Test #%d:\n", ++testno); if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK for (i=0; i<5; i++) { if (str1[i] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[0] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -335,18 +363,21 @@ printf("Test #%d:\n", ++testno); if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK for (i=0; i<5; i++) { if (str1[i] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str1[5] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -362,17 +393,20 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (str2[16] == L'\0' && str2[17] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } rc = memcmp_s(str1, LEN, str2, (17)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- <> -%ls-\n", __FUNCTION__, __LINE__, str1, str2); + ++errs; } @@ -388,17 +422,20 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (str1[sz] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } rc = memcmp_s(str2, LEN, str1, (sz+1)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u Error -%ls- <> -%ls-\n", __FUNCTION__, __LINE__, str2, str1); + ++errs; } /*--------------------------------------------------*/ @@ -414,18 +451,21 @@ printf("Test #%d:\n", ++testno); if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #ifdef SAFE_LIB_STR_NULL_SLACK for (i=0; i<5; i++) { if (str1[i] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } } #else if (str2[0] != L'\0') { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } #endif @@ -442,17 +482,20 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } sz = wcsnlen_s(str1, LEN); if (sz != sz_orig && sz == 14) { printf("%s %u (sz=%lu <> 5) Error rc=%u \n", __FUNCTION__, __LINE__, sz, rc ); + ++errs; } rc = memcmp_s(str1, LEN, str2, (sz)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u -%ls- <> -%ls- (size=%lu) Error rc=%u \n", __FUNCTION__, __LINE__, str1, str2, sz, rc ); + ++errs; } @@ -469,12 +512,14 @@ printf("Test #%d:\n", ++testno); if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } rc = memcmp_s(str1, LEN, str2, (3)*sizeof(wchar_t), &ind ); if (ind != 0) { printf("%s %u -%ls- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } @@ -492,14 +537,16 @@ printf("Test #%d:\n", ++testno); if (rc != ESNOSPC) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } if (*str2 != L'\0') { printf("%s %u -%ls- Error rc=%u \n", __FUNCTION__, __LINE__, str1, rc ); + ++errs; } /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_wcsnlen_s.c b/unittests/test_wcsnlen_s.c index 755adee..5c16e56 100644 --- a/unittests/test_wcsnlen_s.c +++ b/unittests/test_wcsnlen_s.c @@ -64,6 +64,7 @@ extern errno_t wmemset_s (wchar_t *dest, wchar_t value, rsize_t len); int test_wcsnlen_s (void) { errno_t rc; + int errs = 0; unsigned int testno = 0; @@ -76,6 +77,7 @@ printf("Test #%d:\n", ++testno); if (rc != 0) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -86,6 +88,7 @@ printf("Test #%d:\n", ++testno); if (rc != 0) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -98,6 +101,7 @@ printf("Test #%d:\n", ++testno); if (rc != 40) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -110,6 +114,7 @@ printf("Test #%d:\n", ++testno); if (rc != 20) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -122,6 +127,7 @@ printf("Test #%d:\n", ++testno); if (rc != 0) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } @@ -136,6 +142,7 @@ printf("Test #%d:\n", ++testno); if (rc != 1) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -148,9 +155,10 @@ printf("Test #%d:\n", ++testno); if (rc != 2) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); + ++errs; } - return (0); + return errs; } diff --git a/unittests/test_wmemcmp_s.c b/unittests/test_wmemcmp_s.c index 532a569..3617db6 100644 --- a/unittests/test_wmemcmp_s.c +++ b/unittests/test_wmemcmp_s.c @@ -70,9 +70,10 @@ extern errno_t wmemcmp_s (const wchar_t *dest, rsize_t dmax, const wchar_t *src, rsize_t smax, int *diff); -int test_wmemcmp_s() +int test_wmemcmp_s(void) { errno_t rc; + int errs = 0; uint32_t len; int32_t ind; uint32_t i; @@ -91,6 +92,7 @@ int test_wmemcmp_s() if (rc != ESNULLP) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -101,6 +103,7 @@ int test_wmemcmp_s() if (rc != ESNULLP) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -111,6 +114,7 @@ int test_wmemcmp_s() if (rc != ESNULLP) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -121,6 +125,7 @@ int test_wmemcmp_s() if (rc != ESZEROL) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -131,6 +136,7 @@ int test_wmemcmp_s() if (rc != ESZEROL) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -141,6 +147,7 @@ int test_wmemcmp_s() if (rc != ESLEMAX) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -151,6 +158,7 @@ int test_wmemcmp_s() if (rc != ESLEMAX) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -165,17 +173,20 @@ int test_wmemcmp_s() if (rc != EOK) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } if (ind != 0) { printf("%s %u Ind=%d rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } ind = memcmp(mem1, mem2, len*4); if (ind != 0) { printf("%s %u Ind=%d rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -190,17 +201,20 @@ int test_wmemcmp_s() if (rc != EOK) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } if (ind != 0) { printf("%s %u Ind=%d rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } ind = memcmp(mem1, mem2, len*4); if (ind != 0) { printf("%s %u Ind=%d rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -214,17 +228,20 @@ int test_wmemcmp_s() if (rc != EOK) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } if (ind != 0) { printf("%s %u Ind=%d rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } ind = memcmp(mem1, mem2, LEN*4); if (ind != 0) { printf("%s %u Ind=%d rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -240,11 +257,13 @@ int test_wmemcmp_s() if (rc != EOK) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } if (ind <= 0) { printf("%s %u Ind=%d rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } @@ -261,11 +280,13 @@ int test_wmemcmp_s() if (rc != EOK) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } if (ind >= 0) { printf("%s %u Ind=%d rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -281,11 +302,13 @@ int test_wmemcmp_s() if (rc != EOK) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } if (ind >= 0) { printf("%s %u Ind=%d rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -301,11 +324,13 @@ int test_wmemcmp_s() if (rc != EOK) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } if (ind <= 0) { printf("%s %u Ind=%d rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -321,11 +346,13 @@ int test_wmemcmp_s() if (rc != EOK) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } if (ind >= 0) { printf("%s %u Ind=%d rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ @@ -341,15 +368,17 @@ int test_wmemcmp_s() if (rc != EOK) { printf("%s %u Ind=%d Error rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } if (ind <= 0) { printf("%s %u Ind=%d rc=%u \n", __FUNCTION__, __LINE__, ind, rc ); + ++errs; } /*--------------------------------------------------*/ /*--------------------------------------------------*/ - return (0); + return errs; } diff --git a/unittests/test_wmemcpy_s.c b/unittests/test_wmemcpy_s.c index 568b616..ed2a83a 100644 --- a/unittests/test_wmemcpy_s.c +++ b/unittests/test_wmemcpy_s.c @@ -69,6 +69,7 @@ extern errno_t wmemcpy_s(wchar_t* dest, rsize_t dmax, const wchar_t* src, rsize_ int test_wmemcpy_s (void) { errno_t rc; + int errs = 0; uint32_t i; rsize_t len; unsigned int testno = 0; @@ -83,6 +84,7 @@ int test_wmemcpy_s (void) if (rc != ESNULLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -94,6 +96,7 @@ int test_wmemcpy_s (void) if (rc != ESZEROL) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -104,6 +107,7 @@ int test_wmemcpy_s (void) if (rc != ESLEMAX) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -114,6 +118,7 @@ int test_wmemcpy_s (void) if (rc != ESNULLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -124,6 +129,7 @@ int test_wmemcpy_s (void) if (rc != ESZEROL) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -134,6 +140,7 @@ int test_wmemcpy_s (void) if (rc != ESLEMAX) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -144,6 +151,7 @@ int test_wmemcpy_s (void) if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } /*--------------------------------------------------*/ @@ -154,6 +162,7 @@ int test_wmemcpy_s (void) if (rc != ESOVRLP) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } @@ -169,16 +178,19 @@ int test_wmemcpy_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } else { if ( mem1[0] != 40 && mem1[10] != 40) { printf("%d - %d m1[0]=%d m1[10]=%d should be 40 \n", __LINE__, i, mem1[0], mem1[10]); + ++errs; } for (i=1; i<10; i++) { if (mem1[i] != 44) { printf("%d - %d m1=%d should be 44 \n", __LINE__, i, mem1[i]); + ++errs; } } } @@ -195,19 +207,21 @@ int test_wmemcpy_s (void) if (rc == EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); - + ++errs; } else { for (i=0; i m2=%d \n", __LINE__, i, mem1[i], mem2[i]); + ++errs; } } if (mem1[len] != 33 && mem1[len+1] != 33) { printf("%d - %lu m1[len]=%d m1[len+1]=%d \n", __LINE__, len, mem1[len], mem1[len+1]); + ++errs; } } @@ -291,6 +309,7 @@ int test_wmemmove_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } else { /* verify mem1 was copied properly */ @@ -298,6 +317,7 @@ int test_wmemmove_s (void) if (mem1[i] != 44) { printf("%d - %d m1=%d m2=%d \n", __LINE__, i, mem1[i], mem2[i]); + ++errs; } } @@ -315,25 +335,29 @@ int test_wmemmove_s (void) if (rc != EOK) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc); + ++errs; } else { /* verify mem1 was copied properly */ for (i=0; i<10; i++) { - if (mem1[i] != i) { + if ((uint32_t)mem1[i] != i) { printf("%d - %d m1=%d m2=%d \n", __LINE__, i, mem1[i], mem2[i]); + ++errs; } } for (i=10; i