Skip to content

stdlib: Fix maximum # of digits for 32-bit integers - #133

Merged
kostis merged 1 commit into
kostis:masterfrom
wheremyfoodat:fix_digits_macro
Sep 29, 2026
Merged

kostis merged 1 commit into
kostis:masterfrom
wheremyfoodat:fix_digits_macro

Conversation

@wheremyfoodat

@wheremyfoodat wheremyfoodat commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

The maximum 32-bit integer is:

  • 2,147,483,647 (for signed integers)
  • 4,294,967,295 (for unsigned integers)

In both cases, the number is obviously 10 digits instead of 9. This error would randomly cause memory corruptions when running the rand_gen.pcl program, which prints large numbers given the .input file in this repo.

In my case, the memory corruption would cause a segfault on MacOS, despite going unnoticed on Linux

@wheremyfoodat

wheremyfoodat commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

@MarlenaPanagiotakou brought to my attention that the 64-bit case is also wrong (64-bit integers require up to 19 digits for signed integers, or 20 digits for unsigned integers, not 18). In which case, I'd recommend just allocating 20 bytes in case there's ever a language with unsigned integers in this class.

@kostis

kostis commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Thanks @wheremyfoodat @MarlenaPanagiotakou for finding and fixing this problem. Merging.

@kostis
kostis merged commit ddd0d9e into kostis:master Sep 29, 2026
2 checks passed
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.

2 participants