avrdude-dev
[Top][All Lists]
Advanced

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

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


From: anonymous
Subject: [bug #58078] [PATCH] buspirate: remove compound literals (fixes GCC>=9)
Date: Sun, 29 Mar 2020 15:27:41 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0

URL:
  <https://savannah.nongnu.org/bugs/?58078>

                 Summary: [PATCH] buspirate: remove compound literals (fixes
GCC>=9)
                 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: address@hidden
             Open/Closed: Open
                 Release: SVN snapshot
         Discussion Lock: Any
     Programmer hardware: Bus Pirate v3.6a
             Device type: ATMega328P

    _______________________________________________________

Details:

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,
gcc-9-nonworking.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
buspirate-remove-compound-literals.patch).

[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

<http://savannah.nongnu.org/bugs/download.php?file_id=48704>
-------------------------------------------------------
Date: Sun 29 Mar 2020 07:27:39 PM UTC  Name: gcc-9-nonworking.txt  Size: 1KiB 
 By: None

<http://savannah.nongnu.org/bugs/download.php?file_id=48705>
-------------------------------------------------------
Date: Sun 29 Mar 2020 07:27:39 PM UTC  Name:
0001-buspirate-remove-compound-literals-fixes-GCC-9.patch  Size: 3KiB   By:
None

<http://savannah.nongnu.org/bugs/download.php?file_id=48706>

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?58078>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]