Skip to contentSkip to conversation

var: Remove unset check in varnull

PATCH New Herbert Xu 1 participant 1 message Jun 13

lore
Share & tools
lore

Herbert Xu

author
#0 lore raw

PATCH 1/1 var: Remove unset check in varnull

Unset variables always carry two NUL characters at the end so it's safe to call strchrnul in varnull uncondtionally and step past the first NUL character.

src/var.c +2 -1
index 6e0671a..90fc896 100644
@@ -156,7 +156,8 @@ RESET {
 
 static char *varnull(const char *s)
 {
-	return (strchr(s, '=') ?: nullstr - 1) + 1;
+	/* Unset variables always end with two NUL chars. */
+	return strchrnul(s, '=') + 1;
 }
 
 /*
Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt