errno is positive
Make sure we compare errno against positive error codes. The ones in hwclock.c and install.c can have an impact, the rest are unlikely to be hit or in code that isn't widely used. Also check that errno > 0, to help gcc know that we are returning a negative error code.
This commit is contained in:
@@ -190,7 +190,7 @@ int hwclock_is_localtime(void) {
|
||||
truncate_nl(line);
|
||||
local = streq(line, "LOCAL");
|
||||
|
||||
} else if (errno != -ENOENT)
|
||||
} else if (errno != ENOENT)
|
||||
return -errno;
|
||||
|
||||
return local;
|
||||
|
||||
@@ -1637,7 +1637,7 @@ UnitFileState unit_file_get_state(
|
||||
return state;
|
||||
|
||||
r = unit_file_can_install(&paths, root_dir, path, true);
|
||||
if (r < 0 && errno != -ENOENT)
|
||||
if (r < 0 && errno != ENOENT)
|
||||
return r;
|
||||
else if (r > 0)
|
||||
return UNIT_FILE_DISABLED;
|
||||
|
||||
@@ -204,7 +204,7 @@ int socket_address_parse_netlink(SocketAddress *a, const char *s) {
|
||||
|
||||
errno = 0;
|
||||
if (sscanf(s, "%ms %u", &sfamily, &group) < 1)
|
||||
return errno ? -errno : -EINVAL;
|
||||
return errno > 0 ? -errno : -EINVAL;
|
||||
|
||||
family = netlink_family_from_string(sfamily);
|
||||
if (family < 0)
|
||||
|
||||
+1
-1
@@ -5259,7 +5259,7 @@ int get_home_dir(char **_h) {
|
||||
errno = 0;
|
||||
p = getpwuid(u);
|
||||
if (!p)
|
||||
return errno ? -errno : -ESRCH;
|
||||
return errno > 0 ? -errno : -ESRCH;
|
||||
|
||||
if (!path_is_absolute(p->pw_dir))
|
||||
return -EINVAL;
|
||||
|
||||
Reference in New Issue
Block a user