rstudio / httpuv

HTTP and WebSocket server package for R
Other
229 stars 86 forks source link

Allocate one extra byte for snprintf #206

Closed wch closed 5 years ago

wch commented 5 years ago

This fixes a significant warning on CRAN's win-builder:

In file included from websockets.h:12,
                 from webapplication.h:7,
                 from webapplication.cpp:6:
utils.h: In function ‘std::__cxx11::string http_date_string(const time_t&)’:
utils.h:237:25: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=]
   snprintf(res, maxlen, "%s, %02d %s %04d %02d:%02d:%02d GMT",
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
utils.h:237:11: note: ‘snprintf’ output 24 or more bytes (assuming 31) into a destination of size 30
   snprintf(res, maxlen, "%s, %02d %s %04d %02d:%02d:%02d GMT",
   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     day_name.c_str(),
     ~~~~~~~~~~~~~~~~~
     timeptr.tm_mday,
     ~~~~~~~~~~~~~~~~
     month_name.c_str(),
     ~~~~~~~~~~~~~~~~~~~
     timeptr.tm_year + 1900,
     ~~~~~~~~~~~~~~~~~~~~~~~
     timeptr.tm_hour,
     ~~~~~~~~~~~~~~~~
     timeptr.tm_min,
     ~~~~~~~~~~~~~~~
     timeptr.tm_sec
     ~~~~~~~~~~~~~~
   );
   ~        
wch commented 5 years ago

Note that I wasn't able to reproduce the problem locally, with gcc 8.2.0. Based on the docs for snprintf, I think the warning is spurious.

wch commented 5 years ago

After discussion, we decided to just increase maxlen to 50.