uci: Fix extra semicolons warnings
[project/uci.git] / util.c
diff --git a/util.c b/util.c
index f16a378b307ae5468a332bd0427828acec044ff8..8572e8130555c7aff49e8e8b578841b6ef387825 100644 (file)
--- a/util.c
+++ b/util.c
@@ -69,18 +69,22 @@ __private char *uci_strdup(struct uci_context *ctx, const char *str)
  * for names, only alphanum and _ is allowed (shell compatibility)
  * for types, we allow more characters
  */
-__private bool uci_validate_str(const char *str, bool name)
+__private bool uci_validate_str(const char *str, bool name, bool package)
 {
        if (!*str)
                return false;
 
-       while (*str) {
+       for (; *str; str++) {
                unsigned char c = *str;
-               if (!isalnum(c) && c != '_') {
-                       if (name || (c < 33) || (c > 126))
-                               return false;
-               }
-               str++;
+
+               if (isalnum(c) || c == '_')
+                       continue;
+
+               if (c == '-' && package)
+                       continue;
+
+               if (name || (c < 33) || (c > 126))
+                       return false;
        }
        return true;
 }
@@ -217,17 +221,21 @@ __private FILE *uci_open_stream(struct uci_context *ctx, const char *filename, c
 
        ret = flock(fd, (write ? LOCK_EX : LOCK_SH));
        if ((ret < 0) && (errno != ENOSYS))
-               goto error;
+               goto error_close;
 
        ret = lseek(fd, 0, pos);
 
        if (ret < 0)
-               goto error;
+               goto error_unlock;
 
        file = fdopen(fd, (write ? "w+" : "r"));
        if (file)
                goto done;
 
+error_unlock:
+       flock(fd, LOCK_UN);
+error_close:
+       close(fd);
 error:
        UCI_THROW(ctx, UCI_ERR_IO);
 done: