]> code.delx.au - pulseaudio/blobdiff - src/modules/raop/base64.c
Fix up according to Coding Style
[pulseaudio] / src / modules / raop / base64.c
index 8918def8d5c049125edef7e50698e5da095a22b3..37e476285b81be97b61e35d36d25c2b20e35bb60 100644 (file)
@@ -5,7 +5,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
 static const char base64_chars[] =
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
-static int pos(char c)
-{
+static int pos(char c) {
     if (c >= 'A' && c <= 'Z') return c - 'A' + 0;
     if (c >= 'a' && c <= 'z') return c - 'a' + 26;
     if (c >= '0' && c <= '9') return c - '0' + 52;
     if (c == '+') return 62;
     if (c == '/') return 63;
+    return -1;
 }
 
-int pa_base64_encode(const void *data, int size, char **str)
-{
+int pa_base64_encode(const void *data, int size, char **str) {
     char *s, *p;
     int i;
     int c;
@@ -56,7 +55,6 @@ int pa_base64_encode(const void *data, int size, char **str)
 
     p = s = pa_xnew(char, size * 4 / 3 + 4);
     q = (const unsigned char *) data;
-    i = 0;
     for (i = 0; i < size;) {
         c = q[i++];
         c *= 256;
@@ -84,8 +82,7 @@ int pa_base64_encode(const void *data, int size, char **str)
 
 #define DECODE_ERROR 0xffffffff
 
-static unsigned int token_decode(const char *token)
-{
+static unsigned int token_decode(const char *token) {
     int i;
     unsigned int val = 0;
     int marker = 0;
@@ -97,16 +94,19 @@ static unsigned int token_decode(const char *token)
             marker++;
         else if (marker > 0)
             return DECODE_ERROR;
-        else
-            val += pos(token[i]);
+        else {
+            int lpos = pos(token[i]);
+            if (lpos < 0)
+                return DECODE_ERROR;
+            val += lpos;
+        }
     }
     if (marker > 2)
         return DECODE_ERROR;
     return (marker << 24) | val;
 }
 
-int pa_base64_decode(const char *str, void *data)
-{
+int pa_base64_decode(const char *str, void *data) {
     const char *p;
     unsigned char *q;