mbox series

[v3,0/5] Fix strncpy() warnings for GCC8 new -Wstringop-truncation

Message ID 20181218175122.3229-1-philmd@redhat.com
Headers show
Series Fix strncpy() warnings for GCC8 new -Wstringop-truncation | expand

Message

Philippe Mathieu-Daudé Dec. 18, 2018, 5:51 p.m. UTC
GCC 8 new warning prevents builds to success since quite some time.
First report on the mailing list is in July 2018:
https://lists.gnu.org/archive/html/qemu-devel/2018-07/msg03723.html

Various intents has been sent to fix this:
- Incorrectly using g_strlcpy()
  https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg03705.html
  https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg03706.html
- Using assert() and strpadcpy()
  https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg03938.html
- Use #pragma GCC diagnostic ignored "-Wstringop-truncation"
  https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04261.html
- adding an inline wrapper with said pragma in there
  https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04261.html
- -Wno-stringop-truncation is the makefile
  https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04261.html
- Use the 'nonstring' attribute
  https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04493.html

This series add the QEMU_NONSTRING definition and use it.

Regards,

Phil.

Philippe Mathieu-Daudé (5):
  qemu/compiler: Define QEMU_NONSTRING
  block/sheepdog: Use QEMU_NONSTRING for non NUL-terminated arrays
  hw/acpi: Use QEMU_NONSTRING for non NUL-terminated arrays
  migration: Use QEMU_NONSTRING for non NUL-terminated arrays
  migration: Use strnlen() for fixed-size string

 block/sheepdog.c            |  2 +-
 hw/acpi/core.c              |  8 ++++----
 include/hw/acpi/acpi-defs.h |  8 ++++----
 include/qemu/compiler.h     | 15 +++++++++++++++
 migration/global_state.c    |  4 ++--
 5 files changed, 26 insertions(+), 11 deletions(-)

Comments

Philippe Mathieu-Daudé Dec. 18, 2018, 5:54 p.m. UTC | #1
On 12/18/18 6:51 PM, Philippe Mathieu-Daudé wrote:
> GCC 8 new warning prevents builds to success since quite some time.
> First report on the mailing list is in July 2018:
> https://lists.gnu.org/archive/html/qemu-devel/2018-07/msg03723.html
> 
> Various intents has been sent to fix this:
> - Incorrectly using g_strlcpy()
>   https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg03705.html
>   https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg03706.html
> - Using assert() and strpadcpy()
>   https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg03938.html

And I forgot to add here:

  This was the approch taken by the previous v2:
  https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04405.html

> - Use #pragma GCC diagnostic ignored "-Wstringop-truncation"
>   https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04261.html
> - adding an inline wrapper with said pragma in there
>   https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04261.html
> - -Wno-stringop-truncation is the makefile
>   https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04261.html
> - Use the 'nonstring' attribute
>   https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04493.html
> 
> This series add the QEMU_NONSTRING definition and use it.
> 
> Regards,
> 
> Phil.
Michael S. Tsirkin Dec. 18, 2018, 11:08 p.m. UTC | #2
On Tue, Dec 18, 2018 at 06:51:17PM +0100, Philippe Mathieu-Daudé wrote:
> GCC 8 new warning prevents builds to success since quite some time.
> First report on the mailing list is in July 2018:
> https://lists.gnu.org/archive/html/qemu-devel/2018-07/msg03723.html
> 
> Various intents has been sent to fix this:
> - Incorrectly using g_strlcpy()
>   https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg03705.html
>   https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg03706.html
> - Using assert() and strpadcpy()
>   https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg03938.html
> - Use #pragma GCC diagnostic ignored "-Wstringop-truncation"
>   https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04261.html
> - adding an inline wrapper with said pragma in there
>   https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04261.html
> - -Wno-stringop-truncation is the makefile
>   https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04261.html
> - Use the 'nonstring' attribute
>   https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04493.html
> 
> This series add the QEMU_NONSTRING definition and use it.
> 
> Regards,
> 
> Phil.


Reviewed-by: Michael S. Tsirkin <mst@redhat.com>

> Philippe Mathieu-Daudé (5):
>   qemu/compiler: Define QEMU_NONSTRING
>   block/sheepdog: Use QEMU_NONSTRING for non NUL-terminated arrays
>   hw/acpi: Use QEMU_NONSTRING for non NUL-terminated arrays
>   migration: Use QEMU_NONSTRING for non NUL-terminated arrays
>   migration: Use strnlen() for fixed-size string
> 
>  block/sheepdog.c            |  2 +-
>  hw/acpi/core.c              |  8 ++++----
>  include/hw/acpi/acpi-defs.h |  8 ++++----
>  include/qemu/compiler.h     | 15 +++++++++++++++
>  migration/global_state.c    |  4 ++--
>  5 files changed, 26 insertions(+), 11 deletions(-)
> 
> -- 
> 2.17.2
no-reply@patchew.org Dec. 24, 2018, 11:09 p.m. UTC | #3
Patchew URL: https://patchew.org/QEMU/20181218175122.3229-1-philmd@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20181218175122.3229-1-philmd@redhat.com
Type: series
Subject: [Qemu-devel] [PATCH v3 0/5] Fix strncpy() warnings for GCC8 new -Wstringop-truncation

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
df72d7a migration: Use strnlen() for fixed-size string
18211fe migration: Use QEMU_NONSTRING for non NUL-terminated arrays
f5a08ba hw/acpi: Use QEMU_NONSTRING for non NUL-terminated arrays
7d31f0c block/sheepdog: Use QEMU_NONSTRING for non NUL-terminated arrays
5ac217b qemu/compiler: Define QEMU_NONSTRING

=== OUTPUT BEGIN ===
Checking PATCH 1/5: qemu/compiler: Define QEMU_NONSTRING...
WARNING: architecture specific defines should be avoided
#50: FILE: include/qemu/compiler.h:163:
+#if __has_attribute(nonstring)

total: 0 errors, 1 warnings, 21 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 2/5: block/sheepdog: Use QEMU_NONSTRING for non NUL-terminated arrays...
Checking PATCH 3/5: hw/acpi: Use QEMU_NONSTRING for non NUL-terminated arrays...
ERROR: space prohibited before open square bracket '['
#64: FILE: include/hw/acpi/acpi-defs.h:46:
+    uint8_t  oem_id [6] QEMU_NONSTRING; /* OEM identification */

WARNING: Block comments use a leading /* on a separate line
#74: FILE: include/hw/acpi/acpi-defs.h:65:
+    uint8_t  oem_id [6] QEMU_NONSTRING; /* OEM identification */ \

ERROR: space prohibited before open square bracket '['
#74: FILE: include/hw/acpi/acpi-defs.h:65:
+    uint8_t  oem_id [6] QEMU_NONSTRING; /* OEM identification */ \

WARNING: Block comments use a leading /* on a separate line
#75: FILE: include/hw/acpi/acpi-defs.h:66:
+    uint8_t  oem_table_id [8] QEMU_NONSTRING; /* OEM table identification */ \

ERROR: space prohibited before open square bracket '['
#75: FILE: include/hw/acpi/acpi-defs.h:66:
+    uint8_t  oem_table_id [8] QEMU_NONSTRING; /* OEM table identification */ \

WARNING: Block comments use a leading /* on a separate line
#78: FILE: include/hw/acpi/acpi-defs.h:68:
+    uint8_t  asl_compiler_id [4] QEMU_NONSTRING; /* ASL compiler vendor ID */ \

ERROR: space prohibited before open square bracket '['
#78: FILE: include/hw/acpi/acpi-defs.h:68:
+    uint8_t  asl_compiler_id [4] QEMU_NONSTRING; /* ASL compiler vendor ID */ \

total: 4 errors, 3 warnings, 39 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 4/5: migration: Use QEMU_NONSTRING for non NUL-terminated arrays...
Checking PATCH 5/5: migration: Use strnlen() for fixed-size string...
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20181218175122.3229-1-philmd@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com