Code review comment for lp:~nick-dedekind/unity8/StrFTimeFormatter

Lars Karlitski (larsu) wrote :

This patch doesn't check the return value of strftime() and might thus pass an uninitialized buffer into QString().

According to strftime(3), the return value of that function is 0 when the resulting string is longer than the passed in buffer. However, it can also be 0 when the resulting string is legitimately empty. For example, when the format string is "".

I think the best solution is to prepend a " " to the format string. That way, the return value is never smaller than 1, unless there's an error. And then simply return QString(buffer + 1).

You could also use g_date_time_format(), which supports all of the POSIX formats as well.

review: Needs Fixing

« Back to merge proposal