<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/base85.c, branch jch</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=jch</id>
<link rel='self' href='https://git.shady.money/git/atom?h=jch'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2024-12-06T11:20:04Z</updated>
<entry>
<title>global: trivial conversions to fix `-Wsign-compare` warnings</title>
<updated>2024-12-06T11:20:04Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-12-06T10:27:24Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=80c9e70ebe871f0826bc101142c66ff783405100'/>
<id>urn:sha1:80c9e70ebe871f0826bc101142c66ff783405100</id>
<content type='text'>
We have a bunch of loops which iterate up to an unsigned boundary using
a signed index, which generates warnigs because we compare a signed and
unsigned value in the loop condition. Address these sites for trivial
cases and enable `-Wsign-compare` warnings for these code units.

This patch only adapts those code units where we can drop the
`DISABLE_SIGN_COMPARE_WARNINGS` macro in the same step.

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>global: mark code units that generate warnings with `-Wsign-compare`</title>
<updated>2024-12-06T11:20:02Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-12-06T10:27:19Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=41f43b8243f42b9df2e98be8460646d4c0100ad3'/>
<id>urn:sha1:41f43b8243f42b9df2e98be8460646d4c0100ad3</id>
<content type='text'>
Mark code units that generate warnings with `-Wsign-compare`. This
allows for a structured approach to get rid of all such warnings over
time in a way that can be easily measured.

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>base85.h: move declarations for base85.c functions from cache.h</title>
<updated>2023-04-24T19:47:32Z</updated>
<author>
<name>Elijah Newren</name>
<email>newren@gmail.com</email>
</author>
<published>2023-04-22T20:17:13Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=9b5041f647fa5d9921b9b4f8be6b36cb39591166'/>
<id>urn:sha1:9b5041f647fa5d9921b9b4f8be6b36cb39591166</id>
<content type='text'>
Signed-off-by: Elijah Newren &lt;newren@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>base85.c: have SP around arithmetic operators</title>
<updated>2013-10-16T17:27:26Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2013-10-15T22:27:34Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=5f050e3c4ce05de13f24157ca7d3452362e673dc'/>
<id>urn:sha1:5f050e3c4ce05de13f24157ca7d3452362e673dc</id>
<content type='text'>
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Standardize do { ... } while (0) style</title>
<updated>2010-08-12T22:44:51Z</updated>
<author>
<name>Jonathan Nieder</name>
<email>jrnieder@gmail.com</email>
</author>
<published>2010-08-12T22:11:15Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=987460611ab08ebac83ead9a5ee316d3b3823e7f'/>
<id>urn:sha1:987460611ab08ebac83ead9a5ee316d3b3823e7f</id>
<content type='text'>
Signed-off-by: Jonathan Nieder &lt;jrnieder@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'maint-1.6.2' into maint</title>
<updated>2010-01-10T08:51:54Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2010-01-10T08:51:54Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=8fb5d44a47dd3657c8be0de5dcf220935b04e98e'/>
<id>urn:sha1:8fb5d44a47dd3657c8be0de5dcf220935b04e98e</id>
<content type='text'>
* maint-1.6.2:
  base85: Make the code more obvious instead of explaining the non-obvious
  base85: encode_85() does not use the decode table
  base85 debug code: Fix length byte calculation
  checkout -m: do not try to fall back to --merge from an unborn branch

Conflicts:
	diff.c
</content>
</entry>
<entry>
<title>base85: Make the code more obvious instead of explaining the non-obvious</title>
<updated>2010-01-10T06:43:47Z</updated>
<author>
<name>Andreas Gruenbacher</name>
<email>agruen@suse.de</email>
</author>
<published>2010-01-08T13:40:00Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=0606c36a73449e76d8f6133253c1eff291ee8c97'/>
<id>urn:sha1:0606c36a73449e76d8f6133253c1eff291ee8c97</id>
<content type='text'>
Here is another cleanup ...

Signed-off-by: Andreas Gruenbacher &lt;agruen@suse.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>base85: encode_85() does not use the decode table</title>
<updated>2010-01-10T06:43:37Z</updated>
<author>
<name>Andreas Gruenbacher</name>
<email>agruen@suse.de</email>
</author>
<published>2010-01-08T16:22:18Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b0bec518aa4a90485c411cebc7260425271af949'/>
<id>urn:sha1:b0bec518aa4a90485c411cebc7260425271af949</id>
<content type='text'>
Signed-off-by: Andreas Gruenbacher &lt;agruen@suse.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>base85 debug code: Fix length byte calculation</title>
<updated>2010-01-10T06:43:27Z</updated>
<author>
<name>Andreas Gruenbacher</name>
<email>agruen@suse.de</email>
</author>
<published>2010-01-08T13:39:58Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=75b7e16b6ea49d0a0da821373ae5ee3a0ee36f2e'/>
<id>urn:sha1:75b7e16b6ea49d0a0da821373ae5ee3a0ee36f2e</id>
<content type='text'>
Signed-off-by: Andreas Gruenbacher &lt;agruen@suse.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Fix big left-shifts of unsigned char</title>
<updated>2009-06-18T16:22:46Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2009-06-18T00:22:27Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=48fb7deb5bbd87933e7d314b73d7c1b52667f80f'/>
<id>urn:sha1:48fb7deb5bbd87933e7d314b73d7c1b52667f80f</id>
<content type='text'>
Shifting 'unsigned char' or 'unsigned short' left can result in sign
extension errors, since the C integer promotion rules means that the
unsigned char/short will get implicitly promoted to a signed 'int' due to
the shift (or due to other operations).

This normally doesn't matter, but if you shift things up sufficiently, it
will now set the sign bit in 'int', and a subsequent cast to a bigger type
(eg 'long' or 'unsigned long') will now sign-extend the value despite the
original expression being unsigned.

One example of this would be something like

	unsigned long size;
	unsigned char c;

	size += c &lt;&lt; 24;

where despite all the variables being unsigned, 'c &lt;&lt; 24' ends up being a
signed entity, and will get sign-extended when then doing the addition in
an 'unsigned long' type.

Since git uses 'unsigned char' pointers extensively, we actually have this
bug in a couple of places.

I may have missed some, but this is the result of looking at

	git grep '[^0-9 	][ 	]*&lt;&lt;[ 	][a-z]' -- '*.c' '*.h'
	git grep '&lt;&lt;[   ]*24'

which catches at least the common byte cases (shifting variables by a
variable amount, and shifting by 24 bits).

I also grepped for just 'unsigned char' variables in general, and
converted the ones that most obviously ended up getting implicitly cast
immediately anyway (eg hash_name(), encode_85()).

In addition to just avoiding 'unsigned char', this patch also tries to use
a common idiom for the delta header size thing. We had three different
variations on it: "&amp; 0x7fUL" in one place (getting the sign extension
right), and "&amp; ~0x80" and "&amp; 0x7f" in two other places (not getting it
right). Apart from making them all just avoid using "unsigned char" at
all, I also unified them to then use a simple "&amp; 0x7f".

I considered making a sparse extension which warns about doing implicit
casts from unsigned types to signed types, but it gets rather complex very
quickly, so this is just a hack.

Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
