Page MenuHomeFreeBSD

libc: Implement N2680.
ClosedPublic

Authored by des on Sep 5 2023, 7:34 AM.
Tags
None
Referenced Files
Unknown Object (File)
May 6 2024, 1:40 AM
Unknown Object (File)
May 6 2024, 1:40 AM
Unknown Object (File)
May 6 2024, 1:37 AM
Unknown Object (File)
May 6 2024, 1:37 AM
Unknown Object (File)
May 5 2024, 1:42 AM
Unknown Object (File)
May 2 2024, 5:18 AM
Unknown Object (File)
Apr 29 2024, 8:54 AM
Unknown Object (File)
Feb 22 2024, 8:36 AM
Subscribers

Details

Summary

This adds specific width length modifiers in the form of wN and wfN (where N is 8, 16, 32, or 64) which allow printing intN_t and int_fastN_t without resorting to casts or PRI macros.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

des requested review of this revision.Sep 5 2023, 7:34 AM

So this looks like it will work for well formed format strings. Unsure what is supposed to happen for poorly formatted ones, hence the question... I'll leave it up to you if you want to address it or not in this commit though. It could be a lot of rework.

lib/libc/stdio/vfwscanf.c
579

General comment on all of these:

I'm not sure what the spec is for this feature...

But what would something like %w88d do with this code? Is the wXX supposed to be parsed as an int, or is it UB what happens when it's not one of the supported XX?

This revision is now accepted and ready to land.Sep 6 2023, 5:35 PM

handle invalid widths better

This revision now requires review to proceed.Sep 6 2023, 5:59 PM
des marked an inline comment as done.Sep 6 2023, 6:14 PM
des added inline comments.
lib/libc/stdio/vfwscanf.c
579

We're required to support 8, 16, 32, and 64 because we provide int8_t, int16_t, int32_t, and int64_t. We're allowed, but not required, to also support other values of N. I choose not to, which technically means it's UB, but I've made sure we fail in a predictable manner.

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2680.pdf

des marked an inline comment as done.Sep 6 2023, 6:14 PM
emaste added a subscriber: emaste.

It'd be nice to include a brief reference to what N2680 is, in the commit message subject -- something like libc: Implement N2680, sized int format specifiers

This revision is now accepted and ready to land.Sep 7 2023, 1:01 AM

It'd be nice to include a brief reference to what N2680 is, in the commit message subject

image.png (89×859 px, 11 KB)

This revision was automatically updated to reflect the committed changes.
In D41725#951854, @des wrote:

It'd be nice to include a brief reference to what N2680 is, in the commit message subject

image.png (89×859 px, 11 KB)

in the commit message subject, i.e., the first line of the commit message. The commit message should also be wrapped to 72 columns.

I.e.,

libc: Implement N2680, sized int format specifiers

This adds specific width length modifiers in the form of wN and wfN 
(where N is 8, 16, 32, or 64) which allow printing intN_t and int_fastN_t 
without resorting to casts or PRI macros.

instead of

libc: Implement N2680.

This adds specific width length modifiers in the form of wN and wfN (where N is 8, 16, 32, or 64) which allow printing intN_t and int_fastN_t without resorting to casts or PRI macros.