Re: [PATCH v2] symlinks: use unsigned int for flags
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 21, 2026, 18:04 UTC
- Message-ID
- <xmqqzf66u9jj.fsf@gitster.g>
- In-Reply-To
- <20260121162640.424126-1-a3205153416@gmail.com>
Tian Yuchen <a3205153416@gmail.com> writes:
> The 'flags' and 'track_flags' fields in symlinks.c are used > strictly as a collection of bits (using bitwise operators including > &, |, ~). Using a signed integer for bitmasks may lead to undefined > behavior with shift operations and logic errors if the MSB is touched.
Which we do not do, so the "signed can lead to bugs" is a valid concern and moving to unsigned is a good mitigation, but ...
> > Change these fields from 'int' to 'unsigned int' to align with C > standards and typical usage patterns.
... I'd tone it down a bit by replacing "aling with C standards and typical" with "match our", if I were writing this.
Show 11 quoted lines
> > Signed-off-by: Tian Yuchen <a3205153416@gmail.com> > > --- > Changes in v2: > > Decouple definition of 'ret' and 'saved_errno' from 'save_flags'. > 'ret' captures the return value of lstat() which can be -1, so it > must remain signed. Same applies to 'saved_errno'. > > (Thanks to Patrick Steinhardt for spotting this)
Yes, indeed. Thanks.