childPosToCell CLI silently changes zero-padded child positions

Open
#1,306 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c, cli
Domain
cli

Research direction

The position is parsed with PRIi64 in the childPosToCell scanner in src/apps/filters/h3.c, around lines 1187-1195, so padded decimal input is read as octal. Start by reproducing the two commands from the issue against the native CLI and comparing with cellToChildPos. Done means a decided behaviour (decimal parsing or rejection of padded and hex input) with a test added to the CLI test suite and the maintainers' compatibility choice recorded in the issue.

Written by the indexing model from the issue text.

Description

Reproduction

On master at 15920096, with the CLI built from unchanged source using GCC 14.2:

h3 childPosToCell -c 85283473fffffff -r 7 -p 8 -f newline
# 872834709ffffff
h3 childPosToCell -c 85283473fffffff -r 7 -p 08 -f newline
# 872834700ffffff

Both exit successfully. Passing the two cells back to h3 cellToChildPos -c <cell> -r 5 gives positions 8 and 0 respectively. Similarly, 10 and 010 round-trip to 10 and 8; 42 and 042 round-trip to 42 and 34. A script that pads positions can therefore select a different cell without an error.

Expected behavior / compatibility question

The help describes --position as a child position without specifying the numeral base. I expected padded decimal values to select the same child, or to be rejected rather than silently selecting a different one.

The position scanner uses PRIi64 (%i conversion), which recognizes an octal prefix and also accepts explicit hex: 0x10 selects position 16 today. Is C-style base detection intended here, or should the CLI treat padded inputs as decimal? If decimal is intended, should explicit hex remain supported for compatibility?

Verified with the native CLI on Linux. No parser change or CTest run yet.

Dominant language
C
Stars
6.7k
Forks
658
Avg merge
5d 21h
Merged PRs (30d)
12

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from uber/h3

All issues in uber/h3

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.