[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: report a warning
From: |
Gavin Smith |
Subject: |
Re: report a warning |
Date: |
Mon, 9 Jan 2023 18:28:46 +0000 |
On Mon, Jan 09, 2023 at 05:44:05PM +0000, Gavin Smith wrote:
> There have long been compiler warnings about the use of strncat in
> install-info.c but there isn't any indication that the code is actually
> incorrect. This compiler warning seems to be completely bogus. The
> real way the code could be improved is to avoid using strcat or strncat
> altogether.
>
> Rewriting the program to reduce the use of strncat could introduce
> bugs where there weren't any before, for no good reason.
>
> However, in the referenced line in this warning, it seems that strcat could
> be used for exactly the same thing. I'm going to make this change
> just so we stop getting reports.
Done in 78c654093. (Same as Per Bothner's patch in previously linked mail.)
@@ -1626,9 +1626,8 @@ split_entry (const char *entry, char **name, size_t
*name_len,
else
{
/* Just show the rest when there's no newline. */
- size_t length = strlen (ptr);
- strncat (*description, ptr, length);
- ptr += length;
+ strcat (*description, ptr);
+ ptr += strlen (ptr);
}
}
Note that I could not work out how to actually execute this code and
it's possible that it never is. This code is only used when a menu
entry does not end with a newline. Menu entries coming from an Info
file do have newlines at the end, and menu entries specified with
--entry on the command line have a newline appended. I didn't
thoroughly analyse the code to prove it was impossible. If someone
finds a way of triggering this code, we could add a test.
I thought of writing
memmove (*description + strlen (*description), ptr, length + 1)
instead, to avoid finding the length of ptr twice, but this would
be harder to read, so it didn't seem worth it.
strncat is used throughout this program in a way contrary to that
envisioned by the gcc warning, in that the third argument is given
as the number of bytes to be copied.