[bug #58078] [PATCH] buspirate: remove compound literals (fixes GCC>=9)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[bug #58078] [PATCH] buspirate: remove compound literals (fixes GCC>=9)

Kevin Cuzner-2

                 Summary: [PATCH] buspirate: remove compound literals (fixes
                 Project: AVR Downloader/UploaDEr
            Submitted by: None
            Submitted on: Sun 29 Mar 2020 07:27:39 PM UTC
                Category: None
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
         Originator Name: Andrew D'Addesio
        Originator Email: [hidden email]
             Open/Closed: Open
                 Release: SVN snapshot
         Discussion Lock: Any
     Programmer hardware: Bus Pirate v3.6a
             Device type: ATMega328P



Attempting to run the following command on GCC 9.1 or 10:

    avrdude -c buspirate -P /dev/ttyUSB0 -p m328p -U lfuse:r:lfuse.bin:r

results in binary mode failing to start, causing a fallback to ASCII:

    Attempting to initiate BusPirate binary mode...
    (null) mode not confirmed: 'BBIO'
    avrdude: Failed to start binary mode, falling back to ASCII...
    Attempting to initiate BusPirate ASCII mode...
    BusPirate: using ASCII mode
    BusPirate is now configured for SPI
    avrdude: AVR device initialized and ready to accept instructions

GCC 8.3 works fine. See the attached files (gcc-8-working.txt,

I spent yesterday debugging and found the cause to be a use of compound
literals in buspirate_start_mode_bin().

In C99, compound literals only have local scope. This means:

    int main(int argc, char **argv)
        struct Foo {int a, b, c;} *foo;
        if (argc & 0x1) {
            foo = &(struct Foo){1, 2, 3};
        } else {
            foo = &(struct Foo){4, 5, 6};
        printf("a=%d, b=%d, c=%d\n", foo->a, foo->b, foo->c);
        return 0;

is undefined behavior. GCC 9.1 and above will not even initialize the Foo
objects (as they are never used while they are in scope), causing foo to point
to uninitialized memory.

GCC unfortunately does not warn about this [1].

I've created a patch that I confirmed fixes the issue on GCC 9 (see

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89990


File Attachments:

Date: Sun 29 Mar 2020 07:27:39 PM UTC  Name: gcc-8-working.txt  Size: 1KiB  
By: None

Date: Sun 29 Mar 2020 07:27:39 PM UTC  Name: gcc-9-nonworking.txt  Size: 1KiB
 By: None

Date: Sun 29 Mar 2020 07:27:39 PM UTC  Name:
0001-buspirate-remove-compound-literals-fixes-GCC-9.patch  Size: 3KiB   By:



Reply to this item at:


  Message sent via Savannah