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

Remove indirection when calling dbuf_printf #830

Closed
wants to merge 1 commit into from

Conversation

saghul
Copy link
Contributor

@saghul saghul commented Jan 17, 2025

No description provided.

@saghul saghul marked this pull request as draft January 17, 2025 08:58
@chqrlie
Copy link
Collaborator

chqrlie commented Jan 17, 2025

The reason for this indirection is to prevent compiler warnings about the format string not being a string constant.

@saghul
Copy link
Contributor Author

saghul commented Jan 17, 2025

What compiler version triggers it? I haven't seen them in the CI run!

@chqrlie

This comment was marked as outdated.

@saghul saghul marked this pull request as ready for review January 17, 2025 09:33
@saghul
Copy link
Contributor Author

saghul commented Jan 24, 2025

How is that board meeting going? 😅

@chqrlie
Copy link
Collaborator

chqrlie commented Jan 26, 2025

How is that board meeting going? 😅

That was a rocky one...

It is very surprising to me that you were able to remove the indirection: it means the compiler(s) do not emit a warning for code that invokes dbuf_printf with a format that is not a string literal. This is fishy! Did you explicitly disable this warning or did the recent change on the printf_like attribute disable the format string verifications inadvertently?

@saghul
Copy link
Contributor Author

saghul commented Jan 27, 2025

I guess you mean -Wformat-nonliteral ? Looks like that is not enabled even with -Wall, one needs to set -Wformat=2 : https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

Now, if I set that, even without this PR:

/Users/saghul/src/quickjs/libbf.c:3973:44: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
 3973 |                             dbuf_printf(s, fmt, (n - 1) * radix_bits);
      |                                            ^~~
/Users/saghul/src/quickjs/libbf.c:3979:44: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
 3979 |                             dbuf_printf(s, fmt,
      |                                            ^~~
2 errors generated.
make[4]: *** [CMakeFiles/qjs.dir/libbf.c.o] Error 1
make[4]: *** Waiting for unfinished jobs....
/Users/saghul/src/quickjs/quickjs.c:6865:33: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
 6865 |     vsnprintf(buf, sizeof(buf), fmt, ap);
      |                                 ^~~
/Applications/Xcode-16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/include/secure/_stdio.h:75:63: note: expanded from macro 'vsnprintf'
   75 |   __builtin___vsnprintf_chk (str, len, 0, __darwin_obsz(str), format, ap)
      |                                                               ^~~~~~
/Users/saghul/src/quickjs/quickjs.c:6940:35: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
 6940 |     return JS_ThrowTypeError(ctx, fmt,
      |                                   ^~~
/Users/saghul/src/quickjs/quickjs.c:6948:37: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
 6948 |     return JS_ThrowSyntaxError(ctx, fmt,
      |                                     ^~~
3 errors generated.

So it looks like we are alrady in that territory.

@gschwind
Copy link
Contributor

Hello,

maybe some comment around the indirection could be useful such as:
keep it to avoid misleading printf format error

Best regards

@saghul
Copy link
Contributor Author

saghul commented Jan 27, 2025

This PR makes that error surface, yes:

/Users/saghul/src/quickjs/libbf.c:3973:44: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
 3973 |                             dbuf_printf(s, fmt, (n - 1) * radix_bits);
      |                                            ^~~
/Users/saghul/src/quickjs/libbf.c:3979:44: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
 3979 |                             dbuf_printf(s, fmt,
      |                                            ^~~

My point is that we are not compiling with those flags anyway, and we already have the problem in other palces so we are not going to turn that flag on.

@saghul
Copy link
Contributor Author

saghul commented Jan 28, 2025

Closing in favor of #857

@saghul saghul closed this Jan 28, 2025
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

Successfully merging this pull request may close these issues.

3 participants