On 01.10.20 18:38, Bertrand Marquis wrote:
Hi Juergen,

On 14 Sep 2020, at 11:58, Bertrand Marquis <bertrand.marq...@arm.com> wrote:



On 12 Sep 2020, at 14:08, Juergen Gross <jgr...@suse.com> wrote:

Making getBridge() static triggered a build error with some gcc versions:

error: 'strncpy' output may be truncated copying 15 bytes from a string of
length 255 [-Werror=stringop-truncation]

Fix that by using a buffer with 256 bytes instead.

Fixes: 6d0ec053907794 ("tools: split libxenstat into new tools/libs/stat 
directory")
Signed-off-by: Juergen Gross <jgr...@suse.com>
Reviewed-by: Bertrand Marquis <bertrand.marq...@arm.com>

Sorry i have to come back on this one.

I still see an error compiling with Yocto on this one:
|     inlined from 'xenstat_collect_networks' at xenstat_linux.c:306:2:
| xenstat_linux.c:81:6: error: 'strncpy' output may be truncated copying 255 
bytes from a string of length 255 [-Werror=stringop-truncation]
|    81 |      strncpy(result, de->d_name, resultLen);
|       |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To solve it, I need to define devBridge[257] as devNoBrideg.

IMHO this is a real compiler error.

de->d_name is an array of 256 bytes, so doing strncpy() from that to
another array of 256 bytes with a length of 256 won't truncate anything.

Making devBridge one byte longer would be dangerous, as this would do
a strncpy with length of 257 from a source with a length of 256 bytes
only.

BTW, I think Andrew? has tested my patch with a recent gcc which threw
the original error without my patch, and it was fine with the patch.
Either your compiler (assuming you are using gcc) has gained that error
or you are missing an update fixing it.


Juergen

Reply via email to