Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbg macro issues #20

Open
nathanlynch opened this issue Mar 9, 2022 · 1 comment
Open

dbg macro issues #20

nathanlynch opened this issue Mar 9, 2022 · 1 comment

Comments

@nathanlynch
Copy link
Contributor

Couple problems I see with dbg() in syscall.h:

#define dbg(_fmt, _args...)						  \
	do {								  \
		if (dbg_lvl > 0)					  \
			printf("librtas %s(): " _fmt, __func__, ##_args); \
	} while (0)

  1. This seems to defeat the format string type-checking that the compiler can do. cppcheck detects many problems (see below)
  2. printf with the assumption that the output will go somewhere useful or safe is poor practice in a library. syslog may be better?

cppcheck report:

cppcheck --enable=warning .
Checking librtas_src/ofdt.c ...
1/18 files checked 2% done
Checking librtas_src/syscall_calls.c ...
librtas_src/syscall_calls.c:106:2: warning: %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned long'. [invalidPrintfArgType_sint]
 dbg("Return status %d, delaying for %ld ms\n", status, ms);
 ^
librtas_src/syscall_calls.c:704:2: warning: %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %p) = %d\n", parameter, length, data, rc ? rc : status);
 ^
librtas_src/syscall_calls.c:704:2: warning: %d in format string (no. 3) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %p) = %d\n", parameter, length, data, rc ? rc : status);
 ^
librtas_src/syscall_calls.c:744:2: warning: %d in format string (no. 3) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("() = %d, %d, %d, %d, %d, %d, %d, %d\n", rc ? rc : status, *year,
 ^
librtas_src/syscall_calls.c:744:2: warning: %d in format string (no. 4) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("() = %d, %d, %d, %d, %d, %d, %d, %d\n", rc ? rc : status, *year,
 ^
librtas_src/syscall_calls.c:744:2: warning: %d in format string (no. 5) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("() = %d, %d, %d, %d, %d, %d, %d, %d\n", rc ? rc : status, *year,
 ^
librtas_src/syscall_calls.c:744:2: warning: %d in format string (no. 6) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("() = %d, %d, %d, %d, %d, %d, %d, %d\n", rc ? rc : status, *year,
 ^
librtas_src/syscall_calls.c:744:2: warning: %d in format string (no. 7) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("() = %d, %d, %d, %d, %d, %d, %d, %d\n", rc ? rc : status, *year,
 ^
librtas_src/syscall_calls.c:744:2: warning: %d in format string (no. 8) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("() = %d, %d, %d, %d, %d, %d, %d, %d\n", rc ? rc : status, *year,
 ^
librtas_src/syscall_calls.c:744:2: warning: %d in format string (no. 9) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("() = %d, %d, %d, %d, %d, %d, %d, %d\n", rc ? rc : status, *year,
 ^
librtas_src/syscall_calls.c:811:2: warning: %d in format string (no. 5) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%s, 0x%p, %zd, %d) = %d, %d, %d", loc_code ? loc_code : "NULL",
 ^
librtas_src/syscall_calls.c:811:2: warning: %d in format string (no. 7) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%s, 0x%p, %zd, %d) = %d, %d, %d", loc_code ? loc_code : "NULL",
 ^
librtas_src/syscall_calls.c:811:2: warning: %d in format string (no. 8) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%s, 0x%p, %zd, %d) = %d, %d, %d", loc_code ? loc_code : "NULL",
 ^
librtas_src/syscall_calls.c:865:2: warning: %d in format string (no. 4) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %p, %d, %d, %p) = %d, %d\n", subfunc, workarea,
 ^
librtas_src/syscall_calls.c:865:2: warning: %d in format string (no. 5) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %p, %d, %d, %p) = %d, %d\n", subfunc, workarea,
 ^
librtas_src/syscall_calls.c:865:2: warning: %d in format string (no. 8) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %p, %d, %d, %p) = %d, %d\n", subfunc, workarea,
 ^
librtas_src/syscall_calls.c:1167:2: warning: %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour,
 ^
librtas_src/syscall_calls.c:1167:2: warning: %d in format string (no. 3) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour,
 ^
librtas_src/syscall_calls.c:1167:2: warning: %d in format string (no. 4) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour,
 ^
librtas_src/syscall_calls.c:1167:2: warning: %d in format string (no. 5) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour,
 ^
librtas_src/syscall_calls.c:1167:2: warning: %d in format string (no. 6) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour,
 ^
librtas_src/syscall_calls.c:1167:2: warning: %d in format string (no. 7) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour,
 ^
librtas_src/syscall_calls.c:1167:2: warning: %d in format string (no. 8) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour,
 ^
librtas_src/syscall_calls.c:1203:2: warning: %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %p) = %d\n", parameter, data, rc ? rc : status);
 ^
librtas_src/syscall_calls.c:1233:2: warning: %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour,
 ^
librtas_src/syscall_calls.c:1233:2: warning: %d in format string (no. 3) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour,
 ^
librtas_src/syscall_calls.c:1233:2: warning: %d in format string (no. 4) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour,
 ^
librtas_src/syscall_calls.c:1233:2: warning: %d in format string (no. 5) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour,
 ^
librtas_src/syscall_calls.c:1233:2: warning: %d in format string (no. 6) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour,
 ^
librtas_src/syscall_calls.c:1233:2: warning: %d in format string (no. 7) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour,
 ^
librtas_src/syscall_calls.c:1233:2: warning: %d in format string (no. 8) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour,
 ^
librtas_src/syscall_calls.c:1290:2: warning: %d in format string (no. 3) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%p) %d = %d\n", workarea, scope, rc ? rc : status);
 ^
librtas_src/syscall_calls.c:1329:2: warning: %d in format string (no. 3) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
 dbg("(%p) %d = %d\n", workarea, scope, rc ? rc : status);
 ^

@nathanlynch
Copy link
Contributor Author

This seems to defeat the format string type-checking that the compiler can do.

Actually, GCC's -Wformat-signedness (not included in -Wall or -Wformat) does identify the same problems as cppcheck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant