Browse Source

AP_OSD: account for snprintf now null-terminating strings

master
Peter Barker 7 years ago committed by Andrew Tridgell
parent
commit
de3244e26c
  1. 4
      libraries/AP_OSD/AP_OSD_Backend.cpp

4
libraries/AP_OSD/AP_OSD_Backend.cpp

@ -28,7 +28,7 @@ void AP_OSD_Backend::write(uint8_t x, uint8_t y, bool blink, const char *fmt, ..
if (blink && (blink_phase < 2)) { if (blink && (blink_phase < 2)) {
return; return;
} }
char buff[32]; char buff[32+1]; // +1 for snprintf null-termination
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
int res = hal.util->vsnprintf(buff, sizeof(buff), fmt, ap); int res = hal.util->vsnprintf(buff, sizeof(buff), fmt, ap);
@ -43,7 +43,7 @@ void AP_OSD_Backend::write(uint8_t x, uint8_t y, bool blink, const char *fmt, ..
res--; res--;
} }
} }
if (res < int(sizeof(buff))) { if (res < int(sizeof(buff))-1) {
write(x, y, buff); write(x, y, buff);
} }
va_end(ap); va_end(ap);

Loading…
Cancel
Save