URL:
  <http://savannah.nongnu.org/bugs/?28058>

                 Summary: parameter checking in pgm_read_xxx()
                 Project: AVR C Runtime Library
            Submitted by: wek
            Submitted on: Fri 20 Nov 2009 10:32:06 AM GMT
                Category: Feature Request
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Header files
                  Status: None
        Percent Complete: 0%
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
                 Release: Any
           Fixed Release: None

    _______________________________________________________

Details:

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




    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?28058>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/



_______________________________________________
AVR-libc-dev mailing list
AVR-libc-dev@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-libc-dev

Reply via email to