From: Junio C Hamano <gitster@pobox.com>
To: Andrea Monaco <andrea.monaco@autistici.org>
Cc: git@vger.kernel.org
Subject: Re: Possibly wrong assignment in config.c
Date: Wed, 13 Oct 2021 12:14:54 -0700 [thread overview]
Message-ID: <xmqqzgrcg2j5.fsf@gitster.g> (raw)
In-Reply-To: 87pms8rh2h.fsf@autistici.org
Andrea Monaco <andrea.monaco@autistici.org> writes:
> config.c: In function 'git_config_copy_or_rename_section_in_file':
> config.c:3358:17: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
> 3358 | output[0] = '\t';
> | ~~~~~~~~~~^~~~~~
Hmph, with a wider context, I think the tool is pointing at the
assignment found here?
while (fgets(buf, sizeof(buf), config_file)) {
unsigned i;
int length;
int is_section = 0;
char *output = buf;
for (i = 0; buf[i] && isspace(buf[i]); i++)
; /* do nothing */
if (buf[i] == '[') {
/* it's a section */
int offset;
...
offset = section_name_match(&buf[i], old_name);
if (offset > 0) {
...
output += offset + i;
if (strlen(output) > 0) {
...
output -= 1;
output[0] = '\t';
}
} else {
copystr = store_create_section(new_name, &store);
}
}
remove = 0;
}
Inside the "if (buf[i] == '[')" block, i is not negative, and inside
the "if (offset > 0)" block, offset is positive. So "output +=
offset + i", unless offset and i are so huge to cause integer
wraparound, would only be incrementing offset by some positive
integer. So immediately after "output += offset + i", output is at
least buf+1, if not larger, and &output[-1] is at least pointing at
&buf[0], no?
Or is the tool worried about integer addition (offset+i) wrapping
around?
Or I may need a bit more caffeine, perhaps? I am puzzled...
Thanks.
prev parent reply other threads:[~2021-10-13 19:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-13 17:05 Possibly wrong assignment in config.c Andrea Monaco
2021-10-13 19:14 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqzgrcg2j5.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=andrea.monaco@autistici.org \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.