common/snprintf.c: preserve wide integer values - #3598
Conversation
Keep fallback integer formatting at LLONG width. This prevents pointers and long-long values from being truncated through long on LLP64 systems. Handle the signed minimum without overflow and extend TEST_SNPRINTF with pointer and long-long regression comparisons. Fixes networkupstools#1602 AI assistance: OpenAI Codex gpt-5.6-sol was used for repository analysis, implementation, review, drafting and validation. The human contributor reviewed the change and remains responsible for it. Signed-off-by: user01010111 <lapses.50.booster@icloud.com>
|
A ZIP file with standard source tarball and another tarball with pre-built docs for commit 9d8e1f6 is temporarily available: NUT-tarballs-PR-3598.zip. |
|
The CentOS 8/ppc64le OBS failure occurs during RPM database initialisation, before
CentOS 9/ppc64le builds this commit successfully. Could the CentOS 8/ppc64le preinstall image ( |
|
✅ Build nut 2.8.5.5161-master completed (commit ee81f6e695 by @)
|
|
✅ Build nut 2.8.5.5161-master completed (commit ee81f6e695 by @) |
|
OBS scenarios are on Open Build System, following their dependency tree etc. - as often as they regenerate them. I gather there is a regular inability to start the (emulated?) builders for this platform, which is mostly worked around by persistent restarting of the build in their Web-UI... |
jimklimov
left a comment
There was a problem hiding this comment.
I think the signed number support got broken here, the rest seems OK, thanks.
Document why fmtint negates the unsigned magnitude when formatting negative values, including LLONG_MIN. AI assistance: OpenAI Codex gpt-5.6-sol was used for repository analysis, implementation, review, drafting and validation. The human contributor reviewed the change and remains responsible for it. Signed-off-by: user01010111 <lapses.50.booster@icloud.com>
Carry unsigned format arguments in unsigned LLONG from dopr() through fmtint(), rather than converting them through a possibly narrower signed long. Track negativity separately for signed decimal values and keep the magnitude negation in unsigned arithmetic so LLONG_MIN remains defined. Convert pointers through size_t before widening, and extend the built-in comparisons with narrow and wide unsigned extrema. AI assistance: OpenAI Codex gpt-5.6-sol with xhigh reasoning was used for repository analysis, implementation, review, drafting and validation. Anthropic Claude Fable 5 (claude-fable-5) with xhigh reasoning performed an independent adversarial review and produced a prototype used as design evidence. The human contributor reviewed the change and remains responsible for it. Signed-off-by: user01010111 <lapses.50.booster@icloud.com>
|
❌ Build nut 2.8.5.5192-master failed (commit b9e44ad8bc by @) |
|
❌ Build nut 2.8.5.5193-master failed (commit 0e490faa08 by @) |
Summary
unsigned LLONGthrough the fallback formatter, with signedness tracked separately.%o,%u,%xand%Xarguments directly into unsigned storage instead of passing them through a possibly narrower signedlong.%pthroughsize_tbefore widening, avoiding pointer sign extension on conventional 32-bit and LLP64 targets.LLONG_MINis handled without signed overflow.TEST_SNPRINTFwith focusedUINT_MAX,ULONG_MAX,ULLONG_MAX, top-bit hexadecimal and full-width octal comparisons.Fixes #1602
Review follow-up
Wider ABI testing prompted by review found that the previous PR head regressed the narrow unsigned conversions on systems where
longis narrower thanlong long. On native Windows LLP64,%uwithUINT_MAXwas widened through negativelongand printed as18446744073709551615; the%o,%x,%Xand correspondingunsigned longcases failed in the same way.Casting later inside
fmtint()cannot repair a value already changed by the earlier signed conversion. This revision instead keeps unsigned values unsigned fromva_arg()through digit conversion. For signed decimal formats, the caller supplies the converted unsigned value and its sign separately;fmtint()negates only the unsigned value when producing the magnitude. Plain-valueis not used because it overflows forLLONG_MIN.Validation
snprintfandvsnprintfunavailable andHAVE_LONG_LONG_INT=1;make -C common V=1 snprintf.lopassed with GNU99,-pedanticand-Werror, producing a PE x86-64 object.-Wpointer-to-int-cast;LLONG_MIN.make stylecheck, the non-ASCII source check andgit diff --checkpassed.-Wconversion -Wsign-conversionstill reports 11 pre-existing diagnostics in this legacy file; this revision removes the additional signed-to-unsigned diagnostic introduced by the previous PR head and adds none.No upstream CI result is claimed for this revision until it is published.
General C checklist
longmatches pointers orlong long.common/snprintf.canddocs/developers.txtprecedent.AI assistance
OpenAI Codex
gpt-5.6-solwith xhigh reasoning was used for repository analysis, implementation, review, drafting and local/native validation. Anthropic Claude Fable 5 (claude-fable-5) with xhigh reasoning performed an independent adversarial review and produced a prototype used as design evidence. The human contributor reviewed the complete diff and validation evidence and remains responsible for the contribution.