Skip to content

lib/psdriver: Print double coordinates with %f, not %d - #7700

Merged
cwhite911 merged 1 commit into
OSGeo:mainfrom
cwhite911:psdriver-double-format
Jul 14, 2026
Merged

cwhite911 merged 1 commit into
OSGeo:mainfrom
cwhite911:psdriver-double-format

Conversation

@cwhite911

Copy link
Copy Markdown
Contributor

Fixes 6 CodeQL cpp/wrong-type-format-argument alerts (error severity), all in the PS driver:

  • draw_bitmap.c: PS_Bitmap() printed the double globals cur_x, cur_y with %d
  • erase.c: PS_Erase() printed the double fields ps.left, ps.top, ps.right, ps.bot with %d

This is a real bug, not just a style issue: on x86_64 the doubles go into SSE registers while %d reads the integer registers, so the emitted PostScript operators received garbage operands. Before the fix, d.text (with a freetype font) emitted e.g.

16 20 -12276336 -12276336 BITMAP

(glyph size in the position slots, garbage for the rest). After the fix:

322.000000 220.000000 16 20 BITMAP
0.000000 480.000000 640.000000 0.000000 BOX

%f matches how box.c already prints the same BOX procedure, and the BITMAP prolog passes the first two operands to translate, which accepts reals (the integer-only idiv operates on ncols, which stays %d).

Verified by compiling and rendering d.erase -f and d.text with GRASS_RENDER_IMMEDIATE=ps and inspecting the output above.

This is part of a larger effort to work through the open code scanning alerts, grouped into small PRs by issue type.

Written with the assistance of Claude Code.

PS_Bitmap passed the double cur_x and cur_y and PS_Erase passed the
double ps.left, ps.top, ps.right and ps.bot to output() as %d. On
x86_64 this reads the wrong varargs registers, so BITMAP and BOX
received garbage operands. Use %f as box.c already does for the same
BOX procedure.

Fixes 6 CodeQL cpp/wrong-type-format-argument alerts.
@cwhite911
cwhite911 enabled auto-merge (squash) July 14, 2026 14:51
@cwhite911 cwhite911 self-assigned this Jul 14, 2026
@github-actions github-actions Bot added C Related code is in C libraries labels Jul 14, 2026
@cwhite911
cwhite911 merged commit 795f878 into OSGeo:main Jul 14, 2026
24 checks passed
@echoix

echoix commented Jul 14, 2026

Copy link
Copy Markdown
Member

@cwhite911 Please look at this PR: #3551

it was the same file, also about bad argument types, and the review got postponed indefinitely because of an unanswered question. What made this PR resolve that question? Is the other PR still need to be open now, even though line 44 wasn’t changed?

@github-actions github-actions Bot added this to the 8.6.0 milestone Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants