snprintf compile error

Bug #1459459 reported by Crashpilot1000
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
Invalid
Undecided
Unassigned

Bug Description

Hi!
I was just playing around with snprintf because I read an advice that it is generally safer to use in applications because of the possible size limitation and avoiding writing out of buffer.
So I tried to compile an adapted example from here: http://www.cplusplus.com/reference/cstdio/snprintf/
(for later usage in my oled part like here: https://github.com/Crashpilot1000/HarakiriWebstore1/blob/master/src/drv_i2c_lcd.c#L349)

This: (taken from cplusplus.com example)

..
char line[100];
snprintf (line, sizeof(line), "The half of %d is %d", 60, 60/2 );
..
Produced:
/../../../../arm-none-eabi/lib/armv7-m\libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'

Example from my github https://github.com/Crashpilot1000/HarakiriWebstore1/blob/master/src/drv_i2c_lcd.c#L350
this works of course: ... else sprintf(line, "SAT : - FIX : - ");
this ALSO works: ... else snprintf(line, sizeof(line), "SAT : - FIX : - ");
But this doesn't work (same error in the fist line):
    if (FEATURE_GPS) snprintf(line, sizeof(line), "SAT : %d FIX : %d ", GPS_satnum, GPS_fix); // snprintf doesn't work here
    else snprintf(line, sizeof(line), "SAT : - FIX : - ");

I am compiling for cortex-m3 using gcc-arm-none-eabi-4_9-2015q1-20150306-win32 not sure if that is a bug in gcc or between chair and keyboard.
Cheers Rob

Revision history for this message
Tony Liu (mrtoniliu) wrote :

Hi,

Could you provide the command you use to compile and link the example?

BR,
Tony

Revision history for this message
Crashpilot1000 (r-balko) wrote :

Thanks for looking into this but I think the problem is somewhere inside the makefile / linking process https://github.com/Crashpilot1000/HarakiriWebstore1/blob/master/Makefile. I am still using the makefile from baseflight that is a couple of years old. Primarily I was wondering why snprintf was working in the first place but then stumbeled about additional parameters. I reverted back to sprintf that roots back to this: https://github.com/Crashpilot1000/HarakiriWebstore1/blob/master/src/printf.c and rechecked my buffersizes so everything ok here. I don't have the knowledge to comment any further but I stongly believe that it is not the problem of this toolchain here. So my apologies and please close / delete this issue/bugreport.
Cheers Rob.

Tony Liu (mrtoniliu)
Changed in gcc-arm-embedded:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.