]> git.sesse.net Git - vlc/blobdiff - src/misc/mtime.c
msecstotimestr: fix negative numbers handling
[vlc] / src / misc / mtime.c
index e6f9da637a47e2ca03954a633723f12ab0c38ebd..b85c7ef0e3cedca38b14d43142615b18a97f1fa4 100644 (file)
@@ -127,6 +127,13 @@ char *mstrtime( char *psz_buffer, mtime_t date )
  */
 char *secstotimestr( char *psz_buffer, int32_t i_seconds )
 {
+    if( unlikely(i_seconds < 0) )
+    {
+        secstotimestr( psz_buffer + 1, -i_seconds );
+        *psz_buffer = '-';
+        return psz_buffer;
+    }
+
     div_t d;
 
     d = div( i_seconds, 60 );
@@ -137,8 +144,8 @@ char *secstotimestr( char *psz_buffer, int32_t i_seconds )
         snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%u:%02u:%02u",
                  d.quot, d.rem, i_seconds );
     else
-         snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%02u:%02u",
-                   d.rem, i_seconds );
+        snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%02u:%02u",
+                  d.rem, i_seconds );
     return psz_buffer;
 }