]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/avstring.c
avformat: Constify all muxer/demuxers
[ffmpeg] / libavutil / avstring.c
index f03dd251417a7e3459d5df7b7bc59869f6547472..49e8df55aa3bc24d58bccd3c54556114855b4f31 100644 (file)
@@ -136,6 +136,7 @@ end:
     return p;
 }
 
+#if FF_API_D2STR
 char *av_d2str(double d)
 {
     char *str = av_malloc(16);
@@ -143,6 +144,7 @@ char *av_d2str(double d)
         snprintf(str, 16, "%f", d);
     return str;
 }
+#endif
 
 #define WHITESPACES " \n\t\r"
 
@@ -222,12 +224,13 @@ int av_strcasecmp(const char *a, const char *b)
 
 int av_strncasecmp(const char *a, const char *b, size_t n)
 {
-    const char *end = a + n;
     uint8_t c1, c2;
+    if (n <= 0)
+        return 0;
     do {
         c1 = av_tolower(*a++);
         c2 = av_tolower(*b++);
-    } while (a < end && c1 && c1 == c2);
+    } while (--n && c1 && c1 == c2);
     return c1 - c2;
 }
 
@@ -256,12 +259,18 @@ char *av_strireplace(const char *str, const char *from, const char *to)
 
 const char *av_basename(const char *path)
 {
-    char *p = strrchr(path, '/');
-
+    char *p;
 #if HAVE_DOS_PATHS
-    char *q = strrchr(path, '\\');
-    char *d = strchr(path, ':');
+    char *q, *d;
+#endif
 
+    if (!path || *path == '\0')
+        return ".";
+
+    p = strrchr(path, '/');
+#if HAVE_DOS_PATHS
+    q = strrchr(path, '\\');
+    d = strchr(path, ':');
     p = FFMAX3(p, q, d);
 #endif
 
@@ -273,11 +282,11 @@ const char *av_basename(const char *path)
 
 const char *av_dirname(char *path)
 {
-    char *p = strrchr(path, '/');
+    char *p = path ? strrchr(path, '/') : NULL;
 
 #if HAVE_DOS_PATHS
-    char *q = strrchr(path, '\\');
-    char *d = strchr(path, ':');
+    char *q = path ? strrchr(path, '\\') : NULL;
+    char *d = path ? strchr(path, ':')  : NULL;
 
     d = d ? d + 1 : d;
 
@@ -327,17 +336,18 @@ int av_escape(char **dst, const char *src, const char *special_chars,
               enum AVEscapeMode mode, int flags)
 {
     AVBPrint dstbuf;
+    int ret;
 
-    av_bprint_init(&dstbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
+    av_bprint_init(&dstbuf, 1, INT_MAX); /* (int)dstbuf.len must be >= 0 */
     av_bprint_escape(&dstbuf, src, special_chars, mode, flags);
 
     if (!av_bprint_is_complete(&dstbuf)) {
         av_bprint_finalize(&dstbuf, NULL);
         return AVERROR(ENOMEM);
-    } else {
-        av_bprint_finalize(&dstbuf, dst);
-        return dstbuf.len;
     }
+    if ((ret = av_bprint_finalize(&dstbuf, dst)) < 0)
+        return ret;
+    return dstbuf.len;
 }
 
 int av_match_name(const char *name, const char *names)