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)

Submitter:  None
Submitted:  Sun 29 Mar 2020 07:27:39 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Fixed Privacy:  Public
Assigned to:  joerg_wunsch Originator Name:  Andrew D'Addesio
Originator Email:  -email is unavailable- Open/Closed:  Closed
Release:  SVN snapshot Programmer hardware:  Bus Pirate v3.6a
Device type:  ATMega328P

Sat 06 Nov 2021 10:35:06 PM UTC, comment #2: 

Thanks for the detailed analysis, I completely agree.

Fixed in r1455.

Joerg Wunsch <joerg_wunsch>
Group administrator
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:

https://aur.archlinux.org/packages/avrdude-buspirate-bug58078/

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

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

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 joerg_wunsch (Posted a comment)
  • -email is unavailable- added by snowball (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-11-06 joerg_wunsch StatusNone Fixed
        Assigned toNone joerg_wunsch
        Open/ClosedOpen Closed
    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.13-f8d8.
    Corresponding source code