Fix a potential NULL dereference.
[dhcpcd-ui] / src / libdhcpcd / dhcpcd.c
index 9e8c7d9ac82db83eb1de365cac3d623aed665a00..4b9b61e02b7f13c9936f8095d27838deb1e58879 100644 (file)
@@ -374,11 +374,14 @@ dhcpcd_decode_string_escape(char *dst, size_t dlen, const char *src)
                }
                bytes++;
        }
-       if (dst && --dlen == 0) {
-               errno = ENOSPC;
-               return -1;
+
+       if (dst) {
+               if (--dlen == 0) {
+                       errno = ENOSPC;
+                       return -1;
+               }
+               *dst = '\0';
        }
-       *dst = '\0';
        return bytes;
 }