Skip to content

Commit

Permalink
Explicitly state which warnings to ignore in test cases with format s…
Browse files Browse the repository at this point in the history
…trings.

Signed-off-by: Matthias Schulz <mschulz@hilscher.com>
  • Loading branch information
mschulz-at-hilscher authored and rurban committed Apr 16, 2024
1 parent ff9f920 commit 07bee65
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/test_fscanf_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ int test_fscanf_s(void) {
print_msvcrt(use_msvcrt);
#ifndef HAVE_CT_BOS_OVR
EXPECT_BOS("empty stream")
GCC_DIAG_IGNORE(-Wformat-zero-length)
rc = fscanf_s(NULL, "");
GCC_DIAG_RESTORE
init_msvcrt(errno == ESNULLP, &use_msvcrt);
ERREOF_MSVC(ESNULLP, EINVAL);

Expand All @@ -70,7 +72,9 @@ int test_fscanf_s(void) {
/*--------------------------------------------------*/

stuff_stream(" 24");
GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = fscanf_s(stream, "%s %%n", str2, LEN);
GCC_DIAG_RESTORE
#ifdef BSD_LIKE
if (rc != -1) { /* BSD's return -1 on %%n */
printf("%s %u wrong fscanf(\"\",L\"%%n\"): %d\n", __FUNCTION__,
Expand Down Expand Up @@ -100,7 +104,9 @@ int test_fscanf_s(void) {
strcpy(str1, "aaaaaaaaaa");
stuff_stream(str1);

GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = fscanf_s(stream, "%s", str2, LEN);
GCC_DIAG_RESTORE
if (rc != 1) {
printf("flapping tests - abort\n");
return errs;
Expand All @@ -121,7 +127,9 @@ int test_fscanf_s(void) {

stuff_stream("keep it simple");

GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = fscanf_s(stream, "%s", str2, LEN);
GCC_DIAG_RESTORE
ERR(1);
EXPSTR(str2, "keep");

Expand Down Expand Up @@ -154,15 +162,20 @@ int test_fscanf_s(void) {
/*--------------------------------------------------*/

stuff_stream(" 24");
GCC_DIAG_IGNORE(-Wformat)
GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = fscanf_s(stream, "%s %n", str2, LEN, &ind);
GCC_DIAG_RESTORE
ERREOF(EINVAL);

/*--------------------------------------------------*/

str1[0] = '\0';
stuff_stream(str1);

GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = fscanf_s(stream, "%s", str2, LEN);
GCC_DIAG_RESTORE
if (rc != 1) {
printf("flapping tests - abort\n");
return errs;
Expand Down
4 changes: 4 additions & 0 deletions tests/test_printf_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ int test_printf_s(void) {

/*--------------------------------------------------*/

GCC_DIAG_IGNORE(-Wformat-zero-length)
rc = printf_s("");
GCC_DIAG_RESTORE
NEGERR(EOK)

/* TODO
Expand All @@ -51,7 +53,9 @@ int test_printf_s(void) {
/*--------------------------------------------------*/

str1[0] = '\0';
GCC_DIAG_IGNORE(-Wformat)
rc = printf_s("%s%n\n", str1, &ind);
GCC_DIAG_RESTORE
NEGERR(EINVAL)

/*--------------------------------------------------*/
Expand Down
19 changes: 19 additions & 0 deletions tests/test_scanf_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ int test_scanf_s(void) {
print_msvcrt(use_msvcrt);
#ifndef HAVE_CT_BOS_OVR
EXPECT_BOS("empty fmt")
GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = scanf_s(NULL, NULL);
GCC_DIAG_RESTORE
init_msvcrt(errno == ESNULLP, &use_msvcrt);
ERREOF_MSVC(ESNULLP, EINVAL);
#endif
Expand All @@ -62,7 +64,9 @@ int test_scanf_s(void) {
/*--------------------------------------------------*/

stuff_stdin(" 24");
GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = scanf_s("%s %%n", str2, LEN);
GCC_DIAG_RESTORE
#ifdef BSD_LIKE
if (rc != 0) { /* BSD's return -1 on %%n */
printf("%s %u wrong fscanf(\"\",L\"%%n\"): %d\n", __FUNCTION__,
Expand All @@ -77,7 +81,9 @@ int test_scanf_s(void) {
ERRNO(0);

stuff_stdin(" 24");
GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = scanf_s("%s %%n", str2, 6);
GCC_DIAG_RESTORE
if (rc != 1) {
printf("flapping tests - abort\n");
return errs;
Expand Down Expand Up @@ -112,7 +118,9 @@ int test_scanf_s(void) {
len1 = strlen(str1);
stuff_stdin(str1);

GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = scanf_s("%s", str2, LEN);
GCC_DIAG_RESTORE
if (rc != 1) {
printf("flapping tests - abort\n");
return errs;
Expand All @@ -134,7 +142,9 @@ int test_scanf_s(void) {
strcpy(str1, "keep it simple");
stuff_stdin(str1);

GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = scanf_s("%s", str2, LEN);
GCC_DIAG_RESTORE
if (rc != 1) {
printf("flapping tests - abort\n");
return errs;
Expand Down Expand Up @@ -173,7 +183,10 @@ int test_scanf_s(void) {
/*--------------------------------------------------*/

stuff_stdin(" 24");
GCC_DIAG_IGNORE(-Wformat)
GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = scanf_s("%s %n", str2, LEN, &ind);
GCC_DIAG_RESTORE
ERREOF(EINVAL);

/*--------------------------------------------------*/
Expand All @@ -182,7 +195,9 @@ int test_scanf_s(void) {
str2[0] = '\0';
stuff_stdin(str1);

GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = scanf_s("%s", str2, LEN);
GCC_DIAG_RESTORE
if (rc == -1) { /* flapping test */
ERR(-1);
EXPNULL(str2);
Expand All @@ -195,7 +210,9 @@ int test_scanf_s(void) {
str1[0] = '\0';
stuff_stdin(str1);

GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = scanf_s("%s", str2, LEN);
GCC_DIAG_RESTORE
if (rc != -1) {
printf("flapping tests - abort\n");
return errs;
Expand All @@ -213,7 +230,9 @@ int test_scanf_s(void) {
strcpy(str1, "qqweqq");
stuff_stdin(str1);
/* would block reading */
GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = scanf_s("%s", str2, LEN);
GCC_DIAG_RESTORE
#endif

/*--------------------------------------------------*/
Expand Down
2 changes: 2 additions & 0 deletions tests/test_sprintf_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ int test_sprintf_s(void) {

/*--------------------------------------------------*/

GCC_DIAG_IGNORE(-Wformat)
rc = sprintf_s(str1, LEN, "%s", NULL);
GCC_DIAG_RESTORE
ERR(-ESNULLP);
ERRNO_MSVC(0, EINVAL); // ??

Expand Down
17 changes: 17 additions & 0 deletions tests/test_sscanf_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ int test_sscanf_s(void) {
print_msvcrt(use_msvcrt);
#ifndef HAVE_CT_BOS_OVR
EXPECT_BOS("empty fmt")
GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = sscanf_s(str1, NULL, NULL);
GCC_DIAG_RESTORE
init_msvcrt(errno == ESNULLP, &use_msvcrt);
ERREOF_MSVC(ESNULLP, EINVAL);

Expand All @@ -53,7 +55,10 @@ int test_sscanf_s(void) {
/*--------------------------------------------------*/

strcpy(str1, " 24");
GCC_DIAG_IGNORE(-Wformat)
GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = sscanf_s(str1, "%s %n", str2, LEN, &ind);
GCC_DIAG_RESTORE
ERREOF(EINVAL);

rc = sscanf_s(str1, "%%n");
Expand All @@ -64,11 +69,15 @@ int test_sscanf_s(void) {
ERR(1);
ERRNO(0);

GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = sscanf_s(str1, "%s %%n", str2, 6);
GCC_DIAG_RESTORE
ERR(1);
ERRNO(0);

GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = sscanf_s(str1, "%s %%n", str3, 6);
GCC_DIAG_RESTORE
ERR(1);
ERRNO(0);
EXPSTR(str3, "24");
Expand Down Expand Up @@ -97,7 +106,9 @@ int test_sscanf_s(void) {
strcpy(str1, "aaaaaaaaaa");
len1 = strlen(str1);

GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = sscanf_s(str1, "%s", str2, LEN);
GCC_DIAG_RESTORE
ERR(1)
len2 = strlen(str2);
len3 = strlen(str1);
Expand All @@ -114,7 +125,9 @@ int test_sscanf_s(void) {

strcpy(str1, "keep it simple");

GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = sscanf_s(str1, "%s", str2, LEN);
GCC_DIAG_RESTORE
ERR(1);
EXPSTR(str1, "keep it simple")

Expand All @@ -123,7 +136,9 @@ int test_sscanf_s(void) {
str1[0] = '\0';
str2[0] = '\0';

GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = sscanf_s(str1, "%s", str2, LEN);
GCC_DIAG_RESTORE
ERR(-1)
EXPNULL(str1)

Expand All @@ -132,7 +147,9 @@ int test_sscanf_s(void) {
str1[0] = '\0';
strcpy(str2, "keep it simple");

GCC_DIAG_IGNORE(-Wformat-extra-args)
rc = sscanf_s(str1, "%s", str2, LEN);
GCC_DIAG_RESTORE
ERR(-1)
EXPSTR(str1, "")

Expand Down

0 comments on commit 07bee65

Please sign in to comment.