Fixes from clang / scan-build
[freeradius.git] / src / lib / print.c
index 9b214d3..2c14c22 100644 (file)
@@ -35,7 +35,7 @@ RCSID("$Id$")
  *     Note that we don't care about the length of the input string,
  *     because '\0' is an invalid UTF-8 character.
  */
-static int utf8_char(uint8_t *str)
+int fr_utf8_char(const uint8_t *str)
 {
        if (*str < 0x20) return 0;
 
@@ -129,7 +129,7 @@ static int utf8_char(uint8_t *str)
  */
 void fr_print_string(const char *in, size_t inlen, char *out, size_t outlen)
 {
-       uint8_t         *str = (uint8_t *)in;
+       const uint8_t   *str = (const uint8_t *) in;
        int             sp = 0;
        int             utf8 = 0;
 
@@ -144,7 +144,7 @@ void fr_print_string(const char *in, size_t inlen, char *out, size_t outlen)
                 *      Some clients send strings with an off-by-one
                 *      length (confused with strings in C).
                 */
-               if ((inlen == 0) && (*str == 0)) break;
+               if ((inlen == 1) && (*str == 0)) break;
 
                switch (*str) {
                        case '\\':
@@ -176,7 +176,7 @@ void fr_print_string(const char *in, size_t inlen, char *out, size_t outlen)
                        continue;
                }
 
-               utf8 = utf8_char((uint8_t *)str);
+               utf8 = fr_utf8_char(str);
                if (!utf8) {
                        snprintf(out, outlen, "\\%03o", *str);
                        out  += 4;
@@ -241,7 +241,7 @@ int vp_prints_value(char * out, size_t outlen, VALUE_PAIR *vp, int delimitst)
                case PW_TYPE_INTEGER:
                        if ( vp->flags.has_tag ) {
                                /* Attribute value has a tag, need to ignore it */
-                               if ((v = dict_valbyattr(vp->attribute, (vp->vp_integer & 0xffffff)))
+                               if ((v = dict_valbyattr(vp->attribute, vp->vendor, (vp->vp_integer & 0xffffff)))
                                    != NULL)
                                        a = v->name;
                                else {
@@ -252,7 +252,7 @@ int vp_prints_value(char * out, size_t outlen, VALUE_PAIR *vp, int delimitst)
                case PW_TYPE_BYTE:
                case PW_TYPE_SHORT:
                                /* Normal, non-tagged attribute */
-                               if ((v = dict_valbyattr(vp->attribute, vp->vp_integer))
+                               if ((v = dict_valbyattr(vp->attribute, vp->vendor, vp->vp_integer))
                                    != NULL)
                                        a = v->name;
                                else {
@@ -385,14 +385,12 @@ static const char *vp_tokens[] = {
   "<`STRING`>"
 };
 
-const char *vp_print_name(char *buffer, size_t bufsize, int attr)
+const char *vp_print_name(char *buffer, size_t bufsize, int attr, int vendor)
 {
-       int vendor;
        size_t len = 0;
 
        if (!buffer) return NULL;
 
-       vendor = VENDOR(attr);
        if (vendor) {
                DICT_VENDOR *v;
                
@@ -433,10 +431,9 @@ int vp_prints(char *out, size_t outlen, VALUE_PAIR *vp)
        if (!vp) return 0;
 
        name = vp->name;
-       len = 0;
 
        if (!name || !*name) {
-               if (!vp_print_name(namebuf, sizeof(namebuf), vp->attribute)) {
+               if (!vp_print_name(namebuf, sizeof(namebuf), vp->attribute, vp->attribute)) {
                        return 0;
                }
                name = namebuf;