bugAVR Downloader/UploaDEr - Bugs: bug #58078, [PATCH] buspirate: remove compound...


You are not allowed to post comments on this tracker with your current authentication level.

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

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:  -email is unavailable- Open/Closed:  Open
Release:  SVN snapshot Programmer hardware:  Bus Pirate v3.6a
Device type:  ATMega328P

Thu 13 Aug 2020 08:14:07 AM UTC, comment #1: 

I encountered the same issue and can confirm that the patch works. For others on Arch Linux, here's a package with this patch applied:


Excitable Snowball <snowball>
Sun 29 Mar 2020 07:27:39 PM UTC, original submission:  

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



Attached Files
file #48704:  gcc-8-working.txt added by None (1KiB - text/plain)
file #48705:  gcc-9-nonworking.txt added by None (1KiB - text/plain)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by snowball (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-03-29 None Attached File- => Added gcc-8-working.txt, #48704
        Attached File- => Added gcc-9-nonworking.txt, #48705
        Attached File- => Added 0001-buspirate-remove-compound-literals-fixes-GCC-9.patch, #48706

    Back to the top

    Powered by Savane 3.6