<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/parse-options.c, branch v2.51.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.51.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.51.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2025-07-09T15:40:32Z</updated>
<entry>
<title>parse-options: add precision handling for OPTION_COUNTUP</title>
<updated>2025-07-09T15:40:32Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2025-07-09T09:46:28Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c1e616c39b31e78acc595790bf3a9553a022a19d'/>
<id>urn:sha1:c1e616c39b31e78acc595790bf3a9553a022a19d</id>
<content type='text'>
Similar to 09705696f7 (parse-options: introduce precision handling for
`OPTION_INTEGER`, 2025-04-17) support value variables of different sizes
for OPTION_COUNTUP.  Do that by requiring their "precision" to be set,
casting their "value" pointer accordingly and checking whether the value
fits.

Signed-off-by: René Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: add precision handling for OPTION_BITOP</title>
<updated>2025-07-09T15:39:46Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2025-07-09T09:46:20Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=1d918bf2a5eb9d860df1dd115ef2641d7b5870e9'/>
<id>urn:sha1:1d918bf2a5eb9d860df1dd115ef2641d7b5870e9</id>
<content type='text'>
Similar to 09705696f7 (parse-options: introduce precision handling for
`OPTION_INTEGER`, 2025-04-17) support value variables of different sizes
for OPTION_BITOP.  Do that by requiring their "precision" to be set,
casting their "value" pointer accordingly and checking whether the value
fits.

Check if "devfal" fits into an integer variable with the given
"precision", but don't check "extra", as its value is only used to clear
bits, so cannot lead to an overflow.  Not checking continues to allow
e.g., using -1 to clear all bits even if the value variable has a
narrower type than intptr_t.

Signed-off-by: René Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: add precision handling for OPTION_NEGBIT</title>
<updated>2025-07-09T15:39:46Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2025-07-09T09:45:53Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=feeebbf1b7d5ed8761355d354e9529c791b77e7d'/>
<id>urn:sha1:feeebbf1b7d5ed8761355d354e9529c791b77e7d</id>
<content type='text'>
Similar to 09705696f7 (parse-options: introduce precision handling for
`OPTION_INTEGER`, 2025-04-17) support value variables of different sizes
for OPTION_NEGBIT.  Do that by requiring their "precision" to be set,
casting their "value" pointer accordingly and checking whether the value
fits.

Signed-off-by: René Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: add precision handling for OPTION_BIT</title>
<updated>2025-07-09T15:39:28Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2025-07-09T09:45:33Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=5228211c4b92052c0a38f2ab67cd0b87a7baec30'/>
<id>urn:sha1:5228211c4b92052c0a38f2ab67cd0b87a7baec30</id>
<content type='text'>
Similar to 09705696f7 (parse-options: introduce precision handling for
`OPTION_INTEGER`, 2025-04-17) support value variables of different sizes
for OPTION_BIT.  Do that by requiring their "precision" to be set,
casting their "value" pointer accordingly and checking whether the value
fits.

Signed-off-by: René Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: add precision handling for OPTION_SET_INT</title>
<updated>2025-07-09T15:39:26Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2025-07-09T09:45:24Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c898bbc5e4b582c28379bc64b7f9c9ec96106993'/>
<id>urn:sha1:c898bbc5e4b582c28379bc64b7f9c9ec96106993</id>
<content type='text'>
Similar to 09705696f7 (parse-options: introduce precision handling for
`OPTION_INTEGER`, 2025-04-17) support value variables of different sizes
for OPTION_SET_INT.  Do that by requiring their "precision" to be set,
casting their "value" pointer accordingly and checking whether the value
fits.

Factor out the casting code from the part of do_get_value() that handles
OPTION_INTEGER to avoid code duplication.  We're going to use it in the
next patches as well.

Signed-off-by: René Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: add precision handling for PARSE_OPT_CMDMODE</title>
<updated>2025-07-09T15:39:10Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2025-07-09T09:45:14Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=0d3e045b34f38d23e6160ce8aae363f358bd5cdc'/>
<id>urn:sha1:0d3e045b34f38d23e6160ce8aae363f358bd5cdc</id>
<content type='text'>
Build on 09705696f7 (parse-options: introduce precision handling for
`OPTION_INTEGER`, 2025-04-17) to support value variables of different
sizes for PARSE_OPT_CMDMODE options.  Do that by requiring their
"precision" to be set and casting their "value" pointer accordingly.

Call the function that does the raw casting do_get_int_value() to
reserve the name get_int_value() for a more friendly wrapper we're
going to introduce in one of the next patches.

Signed-off-by: René Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: require PARSE_OPT_NOARG for OPTION_BITOP</title>
<updated>2025-07-09T15:39:00Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2025-07-09T09:44:09Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=369e6d94b21d238a203ffb702605f97aca5704c9'/>
<id>urn:sha1:369e6d94b21d238a203ffb702605f97aca5704c9</id>
<content type='text'>
OPTION_BITOP options don't take arguments.  Make sure they are declared
that way using the flag PARSE_OPT_NOARG.

Signed-off-by: René Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: introduce precision handling for `OPTION_UNSIGNED`</title>
<updated>2025-04-17T15:15:16Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2025-04-17T10:49:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=bc288c59298f199348418ca08322046c67c9a0a2'/>
<id>urn:sha1:bc288c59298f199348418ca08322046c67c9a0a2</id>
<content type='text'>
This commit is the equivalent to the preceding commit, but instead of
introducing precision handling for `OPTION_INTEGER` we introduce it for
`OPTION_UNSIGNED`.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: introduce precision handling for `OPTION_INTEGER`</title>
<updated>2025-04-17T15:15:15Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2025-04-17T10:49:40Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=09705696f763bac370ac74926bef137eb712c0c8'/>
<id>urn:sha1:09705696f763bac370ac74926bef137eb712c0c8</id>
<content type='text'>
The `OPTION_INTEGER` option type accepts a signed integer. The type of
the underlying integer is a simple `int`, which restricts the range of
values accepted by such options. But there is a catch: because the
caller provides a pointer to the value via the `.value` field, which is
a simple void pointer. This has two consequences:

  - There is no check whether the passed value is sufficiently long to
    store the entire range of `int`. This can lead to integer wraparound
    in the best case and out-of-bounds writes in the worst case.

  - Even when a caller knows that they want to store a value larger than
    `INT_MAX` they don't have a way to do so.

In practice this doesn't tend to be a huge issue because users typically
don't end up passing huge values to most commands. But the parsing logic
is demonstrably broken, and it is too easy to get the calling convention
wrong.

Improve the situation by introducing a new `precision` field into the
structure. This field gets assigned automatically by `OPT_INTEGER_F()`
and tracks the size of the passed value. Like this it becomes possible
for the caller to pass arbitrarily-sized integers and the underlying
logic knows to handle it correctly by doing range checks. Furthermore,
convert the code to use `strtoimax()` intstead of `strtol()` so that we
can also parse values larger than `LONG_MAX`.

Note that we do not yet assert signedness of the passed variable, which
is another source of bugs. This will be handled in a subsequent commit.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: rename `OPT_MAGNITUDE()` to `OPT_UNSIGNED()`</title>
<updated>2025-04-17T15:15:15Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2025-04-17T10:49:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=785c17df7817df8512d2cb92cfc079ef0b4de27c'/>
<id>urn:sha1:785c17df7817df8512d2cb92cfc079ef0b4de27c</id>
<content type='text'>
With the preceding commit, `OPT_INTEGER()` has learned to support unit
factors. Consequently, the major differencen between `OPT_INTEGER()` and
`OPT_MAGNITUDE()` isn't the support of unit factors anymore, as both of
them do support them now. Instead, the difference is that one handles
signed and the other handles unsigned integers.

Adapt the name of `OPT_MAGNITUDE()` accordingly by renaming it to
`OPT_UNSIGNED()`.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
