Current-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: gcc 7 warning
On Tue, Feb 12, 2019 at 05:46:24PM +0100, Martin Husemann wrote:
> On Tue, Feb 12, 2019 at 04:35:02PM +0000, Patrick Welche wrote:
> > Bemused by:
> >
> > xenpmd.c:90:36: error: '%s' directive output may be truncated writing up to 511 bytes into a region of size 271 [-Werror=format-truncation=]
> > #define BATTERY_INFO_FILE_PATH "/tmp/battery/%s/info"
> > ^
> > xenpmd.c:113:52: note: in expansion of macro 'BATTERY_INFO_FILE_PATH'
> > snprintf(file_name, sizeof(file_name), BATTERY_INFO_FILE_PATH,
> > ^~~~~~~~~~~~~~~~~~~~~~
> > xenpmd.c:113:13: note: '__builtin_snprintf' output between 19 and 530 bytes into a destination of size 284
> > snprintf(file_name, sizeof(file_name), BATTERY_INFO_FILE_PATH,
> > ^
> >
> > while trying to build xentools411. I thought that was the point of
> > snprintf...
>
> Yeah, but mostly gcc is right about warning, as the code in question will
> not guarantee 0 termination for the resulting string.
snprintf *does* guarantee that. You are confusing this with strncpy.
Joerg
Home |
Main Index |
Thread Index |
Old Index