Jump to content
 

twelve12pm

New Member
  • Content Count

    2
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by twelve12pm


  1. On 12/30/2018 at 1:10 PM, Orunmila said:

    I think it is related enough. It is always safer to use snprintf, and in fact many coding standards explicitly prohibits the use of the non-length checking versions of these functions. Unfortunately we have not been able to convince Microchip of the importance of this (yet) and today XC8 V2.0 does not support snprintf, strncpy or any of these safer versions, so if you are on a PIC using XC8 - alas, that is not an option for you 😞

     

    See http://www.elm-chan.org/fsw/strf/xprintf.html for one possible embedded implementation. I've seen others out there...

    • Helpful 1

  2. Not necessarily related to your problem but I always recommend (if your library provides it) to use snprintf() instead of sprintf(). The difference is that snprintf() takes an additional parameter, the size of the string buffer, and as a result of knowing the size of this buffer, it won't overrun it; whereas sprintf() has no idea what is the size of the buffer and may overrun it, hence you always see code using sprintf() passing in big buffers (you used 128 as the size of the buffer) to have lots of "extra space." Much better to use snprintf() and know that the buffer will never be overrun.

×
×
  • Create New...