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

 
 

bug #28058: parameter checking in pgm_read_xxx()

Submitted by:  Jan Waclawek <wek>
Submitted on:  Fri 20 Nov 2009 10:32:06 AM UTC  
 
Category: Feature RequestSeverity: 3 - Normal
Priority: 9 - ImmediateItem Group: Header files
Status: In ProgressPercent Complete: 30%
Assigned to: NoneOpen/Closed: Open
Release: AnyFixed Release: None

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project 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:
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

[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.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 16 Nov 2012 06:59:03 PM UTCarcanumPriority5 - Normal=>9 - Immediate
    Wed 23 Feb 2011 06:20:57 PM UTCarcanumStatusNone=>In Progress
      Percent Complete0%=>30%

    Back to the top


    Powered by Savane 3.1-cleanup