Skip to content

units: avoid division by zero - #1043

Merged
briandfoy merged 1 commit into
briandfoy:masterfrom
mknos:units-div0
Jun 10, 2026
Merged

units: avoid division by zero#1043
briandfoy merged 1 commit into
briandfoy:masterfrom
mknos:units-div0

Conversation

@mknos

@mknos mknos commented Jun 9, 2026

Copy link
Copy Markdown
Contributor
  • The code was too simple-minded because it assumed it was OK to proceed with division when a unit name is not recognised
  • unit_convert() is called after an "unknown unit" error is printed, so just exit the program before delegating to unit_divide() which causes the division error
  • In case $PARSE_ERROR is not set, don't bother printing it

Tests:

  • perl units cm ca ---> arg2 unknown
  • perl units yo 0 ---> arg1 unknown

Old trace:

%perl units h 00000000
Unknown unit 'h'
Uncaught exception from user code:
	Division by zero error at units line 392.
	PerlPowerTools::units::unit_divide(HASH(0x555c5d9032f0), HASH(0x555c5cdba5b0)) called at units line 251
	PerlPowerTools::units::unit_convert("PerlPowerTools::units", undef, HASH(0x555c5d8fdbe8)) called at units line 92
	PerlPowerTools::units::run("PerlPowerTools::units", "h", 00000000) called at units line 79

* The code was too simple-minded because it assumed it was OK to proceed with division when a unit name is not recognised
* unit_convert() is called after an "unknown unit" error is printed, so just exit the program before delegating to unit_divide() which causes the division error
* In case $PARSE_ERROR is not set, don't bother printing it

Tests:
* "perl units cm ca" ---> arg2 unknown
* "perl units yo 0" ---> arg2 unknown
@mknos
mknos temporarily deployed to housekeeping June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@mknos
mknos temporarily deployed to automated_testing June 9, 2026 02:53 — with GitHub Actions Inactive
@github-actions github-actions Bot added Type: enhancement improve a feature that already exists Priority: low get to this whenever Program: units The units program Status: needs verification issue needs to be verified Type: bug an existing feature does not work labels Jun 9, 2026
@briandfoy
briandfoy merged commit ac78257 into briandfoy:master Jun 10, 2026
23 of 24 checks passed
@github-actions github-actions Bot added Status: accepted The fix is accepted and removed Status: needs verification issue needs to be verified Priority: low get to this whenever labels Jun 10, 2026
@briandfoy

Copy link
Copy Markdown
Owner

changes: fix a branch to disallow divide by zero

@briandfoy briandfoy removed the Type: enhancement improve a feature that already exists label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Program: units The units program Status: accepted The fix is accepted Type: bug an existing feature does not work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants