bugAVR C Runtime Library - Bugs: bug #28058, parameter checking in...

 
 

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

bug #28058: parameter checking in pgm_read_xxx()

Submitter:  Jan Waclawek <wek>
Submitted:  Fri 20 Nov 2009 10:32:06 AM UTC
   
 
Category:  Feature Request Severity:  3 - Normal
Priority:  9 - Immediate Item Group:  Header files
Status:  In Progress Assigned to:  None
Percent Complete:  30% Open/Closed:  Open
Release:  Any Fixed Release:  None

Wed 23 Feb 2011 06:20:57 PM UTC, comment #3: 

Renamed strlen_P to __strlen_P, added new inline function strlen_P to avr/pgmspace.h header file, as per comment #2. Committed. Comments #0, #1 still need to be addressed.

Eric Weddington <arcanum>
Group administrator
Sat 22 May 2010 01:01:21 PM UTC, comment #2: 

Although not completely to the topic, as it again is related to <avr/pgmspace> , I would propose also the following addition:

__attribute__((__always_inline__)) static inline size_t strlen_P(PGM_P s);

static inline size_t strlen_P(PGM_P s) {
  return __builtin_constant_p(__builtin_strlen(s))
     ? __builtin_strlen(s) : __strlen_P(s);
}

and rename the existing strlen_P() function to __strlen_P(s) (including the appropriate change in library function).

This allows the compiler to avoid call of the library function when length of string is known at compile time.

The same change could be made to the far counterpart (strlen_PF()), in the unlikely event that Carlos Lamas' library gets included into the official avr-libc.

This item has been discussed on avrfreaks.net.

Jan Waclawek

Jan Waclawek <wek>
Wed 28 Apr 2010 03:20:50 PM UTC, comment #1: 

I would also propose adding the following function to <avr/pgmspace.h>, to allow for proper reading of PROGMEM char-s


__attribute__((__always_inline__)) static char pgm_read_char(PGM_P);
static char pgm_read_char(PGM_P addr) {
  return (char)(__LPM((uint16_t)(addr)));
}


[Please note that in my initial submission, the markup feature eat up the double-underscores around _attribute_ and _always_inline_ to single underscores...]

Jan Waclawek

Jan Waclawek <wek>
Fri 20 Nov 2009 10:32:06 AM UTC, original submission:  

The pgm_read_xxx() functions in <avr/pgmspace.h> are currently implemented as macros, casting the parameter to (uint16_t).

While the parameter is supposed to be a pointer, this enables to use any garbage (read: non-pointer expression used by error) quietly.

Opposed to this are the similar accessing functions in eeprom.h.

It is therefore suggested, that these macros to be replaced by the following constructions:

// #define pgm_read_byte(address_short)    pgm_read_byte_near(address_short)
_attribute_((_always_inline_)) static uint8_t pgm_read_byte(const PROGMEM uint8_t *);
static uint8_t pgm_read_byte(const PROGMEM uint8_t *addr) {
    return __LPM((uint16_t)(addr));
}


// #define pgm_read_word(address_short)    pgm_read_word_near(address_short)
_attribute_((_always_inline_)) static uint16_t pgm_read_word(const PROGMEM uint16_t *);
static uint16_t pgm_read_word(const PROGMEM uint16_t *addr) {
    return __LPM_word((uint16_t)(addr));
}


// #define pgm_read_dword(address_short)   pgm_read_dword_near(address_short)
_attribute_((_always_inline_)) static uint32_t pgm_read_dword(const PROGMEM uint32_t *);
static uint32_t pgm_read_dword(const PROGMEM uint32_t *addr) {
    return __LPM_dword((uint16_t)(addr));
}

I am not expert enough to judge whether the functions may be tagged also with the _pure_ attribute.

A discussion on the topic is on http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=85490 .

Jan Waclawek

Jan Waclawek <wek>

 

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

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-11-16 arcanum Priority5 - Normal 9 - Immediate
    2011-02-23 arcanum StatusNone In Progress
        Percent Complete0% 30%

    Back to the top

    Powered by Savane 3.13-cf05.
    Corresponding source code