]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/avsscanf.c
avformat/wc3movie: use av_packet_alloc() to allocate packets
[ffmpeg] / libavutil / avsscanf.c
index 7c61b860ae123fb9f21f7a47cabaf5f5c4843b6e..b7f0f71c2d5e1837acb4d60a6d0135d8ce412eb4 100644 (file)
@@ -39,7 +39,7 @@ typedef struct FFFILE {
     unsigned char *buf;
     unsigned char *rpos, *rend;
     unsigned char *shend;
-    off_t shlim, shcnt;
+    ptrdiff_t shlim, shcnt;
     void *cookie;
     size_t (*read)(struct FFFILE *, unsigned char *, size_t);
 } FFFILE;
@@ -82,7 +82,7 @@ static int ffuflow(FFFILE *f)
     return EOF;
 }
 
-static void ffshlim(FFFILE *f, off_t lim)
+static void ffshlim(FFFILE *f, ptrdiff_t lim)
 {
     f->shlim = lim;
     f->shcnt = f->buf - f->rpos;
@@ -96,7 +96,7 @@ static void ffshlim(FFFILE *f, off_t lim)
 static int ffshgetc(FFFILE *f)
 {
     int c;
-    off_t cnt = shcnt(f);
+    ptrdiff_t cnt = shcnt(f);
     if (f->shlim && cnt >= f->shlim || (c=ffuflow(f)) < 0) {
         f->shcnt = f->buf - f->rpos + cnt;
         f->shend = 0;
@@ -113,7 +113,7 @@ static int ffshgetc(FFFILE *f)
 }
 
 #define shlim(f, lim) ffshlim((f), (lim))
-#define shgetc(f) (((f)->rpos != (f)->shend) ? *(f)->rpos++ : ffshgetc(f))
+#define shgetc(f) (((f)->rpos < (f)->shend) ? *(f)->rpos++ : ffshgetc(f))
 #define shunget(f) ((f)->shend ? (void)(f)->rpos-- : (void)0)
 
 static const unsigned char table[] = { -1,
@@ -229,9 +229,9 @@ static long long scanexp(FFFILE *f, int pok)
         return LLONG_MIN;
     }
     for (x=0; c-'0'<10U && x<INT_MAX/10; c = shgetc(f))
-        x = 10*x + c-'0';
+        x = 10*x + (c-'0');
     for (y=x; c-'0'<10U && y<LLONG_MAX/100; c = shgetc(f))
-        y = 10*y + c-'0';
+        y = 10*y + (c-'0');
     for (; c-'0'<10U; c = shgetc(f));
     shunget(f);
     return neg ? -y : y;
@@ -241,8 +241,6 @@ static long long scanexp(FFFILE *f, int pok)
 #define LD_B1B_MAX 9007199, 254740991
 #define KMAX 128
 #define MASK (KMAX-1)
-#define CONCAT2(x,y) x ## y
-#define CONCAT(x,y) CONCAT2(x,y)
 
 static double decfloat(FFFILE *f, int c, int bits, int emin, int sign, int pok)
 {
@@ -349,9 +347,10 @@ static double decfloat(FFFILE *f, int c, int bits, int emin, int sign, int pok)
 
     /* Optimize small to mid-size integers (even in exp. notation) */
     if (lnz<9 && lnz<=rp && rp < 18) {
+        int bitlim;
         if (rp == 9) return sign * (double)x[0];
         if (rp < 9) return sign * (double)x[0] / p10s[8-rp];
-        int bitlim = bits-3*(int)(rp-9);
+        bitlim = bits-3*(int)(rp-9);
         if (bitlim>30 || x[0]>>bitlim==0)
             return sign * (double)x[0] * p10s[rp-10];
     }
@@ -455,8 +454,8 @@ static double decfloat(FFFILE *f, int c, int bits, int emin, int sign, int pok)
 
     /* Calculate bias term to force rounding, move out lower bits */
     if (bits < DBL_MANT_DIG) {
-        bias = copysignl(scalbn(1, 2*DBL_MANT_DIG-bits-1), y);
-        frac = fmodl(y, scalbn(1, DBL_MANT_DIG-bits));
+        bias = copysign(scalbn(1, 2*DBL_MANT_DIG-bits-1), y);
+        frac = fmod(y, scalbn(1, DBL_MANT_DIG-bits));
         y -= frac;
         y += bias;
     }
@@ -474,7 +473,7 @@ static double decfloat(FFFILE *f, int c, int bits, int emin, int sign, int pok)
             else
                 frac += 0.75*sign;
         }
-        if (DBL_MANT_DIG-bits >= 2 && !fmodl(frac, 1))
+        if (DBL_MANT_DIG-bits >= 2 && !fmod(frac, 1))
             frac++;
     }
 
@@ -482,7 +481,7 @@ static double decfloat(FFFILE *f, int c, int bits, int emin, int sign, int pok)
     y -= bias;
 
     if ((e2+DBL_MANT_DIG & INT_MAX) > emax-5) {
-        if (fabs(y) >= CONCAT(0x1p, DBL_MANT_DIG)) {
+        if (fabs(y) >= pow(2, DBL_MANT_DIG)) {
             if (denormal && bits==DBL_MANT_DIG+e2-emin)
                 denormal = 0;
             y *= 0.5;
@@ -492,7 +491,7 @@ static double decfloat(FFFILE *f, int c, int bits, int emin, int sign, int pok)
             errno = ERANGE;
     }
 
-    return scalbnl(y, e2);
+    return scalbn(y, e2);
 }
 
 static double hexfloat(FFFILE *f, int bits, int emin, int sign, int pok)
@@ -596,7 +595,7 @@ static double hexfloat(FFFILE *f, int bits, int emin, int sign, int pok)
     }
 
     if (bits < DBL_MANT_DIG)
-        bias = copysignl(scalbn(1, 32+DBL_MANT_DIG-bits-1), sign);
+        bias = copysign(scalbn(1, 32+DBL_MANT_DIG-bits-1), sign);
 
     if (bits<32 && y && !(x&1)) x++, y=0;
 
@@ -605,7 +604,7 @@ static double hexfloat(FFFILE *f, int bits, int emin, int sign, int pok)
 
     if (!y) errno = ERANGE;
 
-    return scalbnl(y, e2);
+    return scalbn(y, e2);
 }
 
 static double fffloatscan(FFFILE *f, int prec, int pok)
@@ -738,7 +737,7 @@ static int ff_vfscanf(FFFILE *f, const char *fmt, va_list ap)
     int matches=0;
     unsigned long long x;
     double y;
-    off_t pos = 0;
+    ptrdiff_t pos = 0;
     unsigned char scanset[257];
     size_t i;