Changeset - r26336:7c7912ebd301
[Not reviewed]
master
0 1 0
glx22 - 2 years ago 2022-08-23 14:50:59
glx@openttd.org
Fix #9974, aa5a8fe: strftime buffer maxsize is off by one

strftime() return value doesn't count NULL character, but buffer size must include it.
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/walltime_func.h
Show inline comments
 
@@ -56,25 +56,25 @@ struct Time {
 
	 * @return The number of characters that were written to the buffer.
 
	 */
 
	static inline size_t Format(char *buffer, const char *last, const char *format) NOACCESS(2) WARN_TIME_FORMAT(3)
 
	{
 
		std::tm time_struct = T::ToTimeStruct(time(nullptr));
 
#ifndef _MSC_VER
 
		/* GCC bug #39438; unlike for printf where the appropriate attribute prevent the
 
		 * "format non literal" warning, that does not happen for strftime. Even though
 
		 * format warnings will be created for invalid strftime formats. */
 
#pragma GCC diagnostic push
 
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
 
#endif /* _MSC_VER */
 
		return strftime(buffer, last - buffer, format, &time_struct);
 
		return strftime(buffer, last - buffer + 1, format, &time_struct);
 
#ifndef _MSC_VER
 
#pragma GCC diagnostic pop
 
#endif /* _MSC_VER */
 
	}
 
};
 

	
 
/** Wall clock time functionality using the local time zone. */
 
using LocalTime = Time<LocalTimeToStruct>;
 
/** Wall clock time functionality using the UTC time zone. */
 
using UTCTime = Time<UTCTimeToStruct>;
 

	
 
#endif
0 comments (0 inline, 0 general)