[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] tests/cpu-policy: fix format-overflow warning by null terminating strings


  • To: "christopher.w.clark@xxxxxxxxx" <christopher.w.clark@xxxxxxxxx>
  • From: Jan Beulich <JBeulich@xxxxxxxx>
  • Date: Thu, 25 Jul 2019 10:03:26 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=suse.com;dmarc=pass action=none header.from=suse.com;dkim=pass header.d=suse.com;arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0BRqYAjOKXtpmbCJWGJY0duPcZghRuvCJ3XV/EdLOiA=; b=bkWlLx5pJgVZ+jkoSO5woS4OF8GqQ8MI/xJuGvsE2ZDknrlr4wEOz7+m7vtG/bc4/cTr0KdTz1OGpJVtPLl6cAZbnT+4qDJWY789So9u38zik6DJeAfEAXabiXg1sILKi8/2z+fOm22reX2W5sF1erfrcl6Vq+HLwfO8Zm5DgSuxmCzH8BU3sOUzPGMIiunQagT+qhRYMz4JYYF3Ivndh6fKNizAK+luZjX3mGN7fiCIKg/7bydSBS87tr5bBEVpy5pu2OJg53/s8aiR47ZdY6CddrCmkjCZn+/GILWZc0W/LlXIIwFgOLfSZ0Rf39Fs9xjBmOXmu02LUV/Sj0k53w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DgZ6H/c++uVVMggGNajlyNF3hQaHtgVPq0TPSpMlCuedRw0Ld+VVNZZQsGuWOyUIJxtM3SXoT9tB7jfIJgYfLI3o3X1/y3DXyisNB7oa+bOT1fD4pwU7SGozEU70zUzn+b54OJ7rqZgsinA21qn04VbvubSCyqTiWO1G7P2s9dEWHPbK8mh3qICeXZR+7zqAyU+uwR7YgA6j6ILH0bOzPvRP8hpPl7eyAkELxB0T6yw9CVgaCF8gN/7YPd9fXtprohJYj3HQKRBEOVFwYZtO/kzk3xuADun+v06NmA/NHfzYSj6KXBvGfR3pzaZgpdJ0IdzR24MZbHlbt5zSgVS3jw==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=JBeulich@xxxxxxxx;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Ian Jackson <ian.jackson@xxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Thu, 25 Jul 2019 10:04:52 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHVQoNqxP3NLSDaSUO4Yjwj1hPOv6bbG1gA
  • Thread-topic: [PATCH] tests/cpu-policy: fix format-overflow warning by null terminating strings

On 25.07.2019 02:53, christopher.w.clark@xxxxxxxxx wrote:
> gcc 9.1.0 reports:
> 
> | test-cpu-policy.c:64:18: error: '%.12s' directive argument is not a 
> nul-terminated string [-Werror=format-overflow=]
> |    64 |             fail("  Test '%.12s', expected vendor %u, got %u\n",
> |       |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> | test-cpu-policy.c:20:12: note: in definition of macro 'fail'
> |    20 |     printf(fmt, ##__VA_ARGS__);                 \
> |       |            ^~~
> | test-cpu-policy.c:64:27: note: format string is defined here
> |    64 |             fail("  Test '%.12s', expected vendor %u, got %u\n",
> |       |                           ^~~~~
> | test-cpu-policy.c:44:7: note: referenced argument declared here
> |    44 |     } tests[] = {
> |       |       ^~~~~

I must be missing something here: %.12s says that no more than 12
bytes are to be read from the string. There's nul terminator
required. This is what the standard says

"Characters from the array are written up to (but not including)
  the terminating null character. If the precision is specified, no
  more than that many bytes are written. If the precision is not
  specified or is greater than the size of the array, the array
  shall contain a null character."

For the moment it looks to me as if the compiler was wrong to
complain.

Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.