]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - string.c
Fix various dead stores found by the clang static analyzer.
[paraslash.git] / string.c
index 752fb8f945d1a381b7b7af4e65ed56b646df8d47..eb458dad1b380d231a653c023dcc66646ebb8c98 100644 (file)
--- a/string.c
+++ b/string.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004-2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2004-2009 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -59,9 +59,10 @@ __must_check __malloc void *para_realloc(void *p, size_t size)
  */
 __must_check __malloc void *para_malloc(size_t size)
 {
-       assert(size);
-       void *p = malloc(size);
+       void *p;
 
+       assert(size);
+       p = malloc(size);
        if (!p) {
                PARA_EMERG_LOG("malloc failed (size = %zu),  aborting\n",
                        size);
@@ -291,9 +292,9 @@ __must_check __malloc char *para_homedir(void)
  *
  * \return The number of substrings found in \a args.
  */
-__must_check unsigned split_args(char *args, char *** const argv_ptr, const char *delim)
+unsigned split_args(char *args, char *** const argv_ptr, const char *delim)
 {
-       char *p = args;
+       char *p;
        char **argv;
        size_t n = 0, i, j;
 
@@ -327,27 +328,6 @@ __must_check unsigned split_args(char *args, char *** const argv_ptr, const char
        return n;
 }
 
-/**
- * Ensure that file descriptors 0, 1, and 2 are valid.
- *
- * Common approach that opens /dev/null until it gets a file descriptor greater
- * than two.
- *
- * \sa okir's Black Hats Manual.
- */
-void valid_fd_012(void)
-{
-       while (1) {
-               int fd = open("/dev/null", O_RDWR);
-               if (fd < 0)
-                       exit(EXIT_FAILURE);
-               if (fd > 2) {
-                       close(fd);
-                       break;
-               }
-       }
-}
-
 /**
  * Get the own hostname.
  *
@@ -606,3 +586,22 @@ int para_atoi32(const char *str, int32_t *value)
        *value = tmp;
        return 1;
 }
+
+int get_loglevel_by_name(const char *txt)
+{
+       if (!strcasecmp(txt, "debug"))
+               return LL_DEBUG;
+       if (!strcasecmp(txt, "info"))
+               return LL_INFO;
+       if (!strcasecmp(txt, "notice"))
+               return LL_NOTICE;
+       if (!strcasecmp(txt, "warning"))
+               return LL_WARNING;
+       if (!strcasecmp(txt, "error"))
+               return LL_ERROR;
+       if (!strcasecmp(txt, "crit"))
+               return LL_CRIT;
+       if (!strcasecmp(txt, "emerg"))
+               return LL_EMERG;
+       return -1;
+}