Fix aperture macro 0X parsed as hex float instead of multiplication#285
Merged
spe-ciellt merged 1 commit intogerbv:developfrom Feb 27, 2026
Merged
Conversation
C99's strtod() interprets "0X25.4" as a hexadecimal floating-point literal (= 37.25) instead of letting the parser handle X as gerbv's multiplication operator. This causes expressions like "0X25.4+90" to evaluate to 127.25 instead of the correct 0 * 25.4 + 90 = 90. Add an early check in gerb_fgetdouble() to detect when the input starts with "0x" or "0X" and return 0.0 while advancing past only the "0". The x/X is then correctly handled as multiplication by the aperture macro expression parser. This is safe for all callers since Gerber format never uses hexadecimal numbers. Fixes gerbv#253
Contributor
|
Thank you for this patch. If this is good enough I apply it else I will leave comments. |
Contributor
|
Looks simple enough. There is the reading more data than maybe available, but I guess it is done in more places in gerbv. An overhaul on how data is read might be in its place. |
This was referenced Feb 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gerb_fgetdouble()misparsing expressions like0X25.4+90as hexadecimal floating-point literals (C99strtodinterprets0X25.4as 37.25) instead of letting the aperture macro parser handleXas the multiplication operator0x/0Xprefix that returns0.0and advances past only the0, so the expression correctly evaluates as0 × 25.4 + 90 = 90Test plan
test-amacro-hex-expression.gbxexercises the0X25.4+90expression in a LINE21 rotation parametertest-amacro-hex-expression.pngincluded — shows rectangle at 90° rotation (not ~127°)Fixes #253