From f56e2a1b3a00369ff8440555098047974458795c Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sun, 21 Feb 2021 16:02:50 -0600 Subject: [PATCH] Maintenance: nmea overflow prevention --- src/Network/nmea.cxx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Network/nmea.cxx b/src/Network/nmea.cxx index bd7af758a..f8565b88b 100644 --- a/src/Network/nmea.cxx +++ b/src/Network/nmea.cxx @@ -136,12 +136,12 @@ bool FGNMEA::gen_message() double altitude_ft = mFdm.get_Altitude(); - char date[10]; + char date[16]; { - int year = t->getGmt()->tm_year; - while ( year >= 100 ) { year -= 100; } - snprintf( date, sizeof(date), "%02d%02d%02d", t->getGmt()->tm_mday, - t->getGmt()->tm_mon+1, year ); + unsigned short tm_mday = t->getGmt()->tm_mday; + unsigned short tm_mon = t->getGmt()->tm_mon + 1; + unsigned short tm_year = t->getGmt()->tm_year % 100; + snprintf(date, sizeof(date), "%02u%02u%02u", tm_mday, tm_mon, tm_year); } char magvar[10];