Merge pull request #2357 from keszybz/warnings-2
Remove gcc warnings v2
This commit is contained in:
@@ -2051,7 +2051,7 @@ int btrfs_subvol_get_parent(int fd, uint64_t subvol_id, uint64_t *ret) {
|
||||
|
||||
args.key.nr_items = 256;
|
||||
if (ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args) < 0)
|
||||
return -errno;
|
||||
return negative_errno();
|
||||
|
||||
if (args.key.nr_items <= 0)
|
||||
break;
|
||||
|
||||
@@ -93,7 +93,7 @@ int cg_read_pid(FILE *f, pid_t *_pid) {
|
||||
if (feof(f))
|
||||
return 0;
|
||||
|
||||
return errno ? -errno : -EIO;
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
}
|
||||
|
||||
if (ul <= 0)
|
||||
@@ -648,7 +648,7 @@ int cg_trim(const char *controller, const char *path, bool delete_root) {
|
||||
if (nftw(fs, trim_cb, 64, FTW_DEPTH|FTW_MOUNT|FTW_PHYS) != 0) {
|
||||
if (errno == ENOENT)
|
||||
r = 0;
|
||||
else if (errno != 0)
|
||||
else if (errno > 0)
|
||||
r = -errno;
|
||||
else
|
||||
r = -EIO;
|
||||
@@ -2091,7 +2091,7 @@ int cg_kernel_controllers(Set *controllers) {
|
||||
if (feof(f))
|
||||
break;
|
||||
|
||||
if (ferror(f) && errno != 0)
|
||||
if (ferror(f) && errno > 0)
|
||||
return -errno;
|
||||
|
||||
return -EBADMSG;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "fd-util.h"
|
||||
#include "macro.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
|
||||
int clock_get_hwclock(struct tm *tm) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
@@ -121,7 +122,8 @@ int clock_set_timezone(int *min) {
|
||||
* have read from the RTC.
|
||||
*/
|
||||
if (settimeofday(tv_null, &tz) < 0)
|
||||
return -errno;
|
||||
return negative_errno();
|
||||
|
||||
if (min)
|
||||
*min = minutesdelta;
|
||||
return 0;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "macro.h"
|
||||
|
||||
static const struct errno_name* lookup_errno(register const char *str,
|
||||
register unsigned int len);
|
||||
register unsigned int len);
|
||||
|
||||
#include "errno-from-name.h"
|
||||
#include "errno-to-name.h"
|
||||
@@ -48,8 +48,9 @@ int errno_from_name(const char *name) {
|
||||
|
||||
sc = lookup_errno(name, strlen(name));
|
||||
if (!sc)
|
||||
return 0;
|
||||
return -EINVAL;
|
||||
|
||||
assert(sc->id > 0);
|
||||
return sc->id;
|
||||
}
|
||||
|
||||
|
||||
+19
-34
@@ -119,16 +119,18 @@ char *cescape(const char *s) {
|
||||
return cescape_length(s, strlen(s));
|
||||
}
|
||||
|
||||
int cunescape_one(const char *p, size_t length, char *ret, uint32_t *ret_unicode) {
|
||||
int cunescape_one(const char *p, size_t length, uint32_t *ret, bool *eight_bit) {
|
||||
int r = 1;
|
||||
|
||||
assert(p);
|
||||
assert(*p);
|
||||
assert(ret);
|
||||
|
||||
/* Unescapes C style. Returns the unescaped character in ret,
|
||||
* unless we encountered a \u sequence in which case the full
|
||||
* unicode character is returned in ret_unicode, instead. */
|
||||
/* Unescapes C style. Returns the unescaped character in ret.
|
||||
* Sets *eight_bit to true if the escaped sequence either fits in
|
||||
* one byte in UTF-8 or is a non-unicode literal byte and should
|
||||
* instead be copied directly.
|
||||
*/
|
||||
|
||||
if (length != (size_t) -1 && length < 1)
|
||||
return -EINVAL;
|
||||
@@ -190,7 +192,8 @@ int cunescape_one(const char *p, size_t length, char *ret, uint32_t *ret_unicode
|
||||
if (a == 0 && b == 0)
|
||||
return -EINVAL;
|
||||
|
||||
*ret = (char) ((a << 4U) | b);
|
||||
*ret = (a << 4U) | b;
|
||||
*eight_bit = true;
|
||||
r = 3;
|
||||
break;
|
||||
}
|
||||
@@ -217,16 +220,7 @@ int cunescape_one(const char *p, size_t length, char *ret, uint32_t *ret_unicode
|
||||
if (c == 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (c < 128)
|
||||
*ret = c;
|
||||
else {
|
||||
if (!ret_unicode)
|
||||
return -EINVAL;
|
||||
|
||||
*ret = 0;
|
||||
*ret_unicode = c;
|
||||
}
|
||||
|
||||
*ret = c;
|
||||
r = 5;
|
||||
break;
|
||||
}
|
||||
@@ -258,16 +252,7 @@ int cunescape_one(const char *p, size_t length, char *ret, uint32_t *ret_unicode
|
||||
if (!unichar_is_valid(c))
|
||||
return -EINVAL;
|
||||
|
||||
if (c < 128)
|
||||
*ret = c;
|
||||
else {
|
||||
if (!ret_unicode)
|
||||
return -EINVAL;
|
||||
|
||||
*ret = 0;
|
||||
*ret_unicode = c;
|
||||
}
|
||||
|
||||
*ret = c;
|
||||
r = 9;
|
||||
break;
|
||||
}
|
||||
@@ -309,6 +294,7 @@ int cunescape_one(const char *p, size_t length, char *ret, uint32_t *ret_unicode
|
||||
return -EINVAL;
|
||||
|
||||
*ret = m;
|
||||
*eight_bit = true;
|
||||
r = 3;
|
||||
break;
|
||||
}
|
||||
@@ -342,7 +328,7 @@ int cunescape_length_with_prefix(const char *s, size_t length, const char *prefi
|
||||
for (f = s, t = r + pl; f < s + length; f++) {
|
||||
size_t remaining;
|
||||
uint32_t u;
|
||||
char c;
|
||||
bool eight_bit = false;
|
||||
int k;
|
||||
|
||||
remaining = s + length - f;
|
||||
@@ -365,7 +351,7 @@ int cunescape_length_with_prefix(const char *s, size_t length, const char *prefi
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
k = cunescape_one(f + 1, remaining - 1, &c, &u);
|
||||
k = cunescape_one(f + 1, remaining - 1, &u, &eight_bit);
|
||||
if (k < 0) {
|
||||
if (flags & UNESCAPE_RELAX) {
|
||||
/* Invalid escape code, let's take it literal then */
|
||||
@@ -377,14 +363,13 @@ int cunescape_length_with_prefix(const char *s, size_t length, const char *prefi
|
||||
return k;
|
||||
}
|
||||
|
||||
if (c != 0)
|
||||
/* Non-Unicode? Let's encode this directly */
|
||||
*(t++) = c;
|
||||
else
|
||||
/* Unicode? Then let's encode this in UTF-8 */
|
||||
t += utf8_encode_unichar(t, u);
|
||||
|
||||
f += k;
|
||||
if (eight_bit)
|
||||
/* One byte? Set directly as specified */
|
||||
*(t++) = u;
|
||||
else
|
||||
/* Otherwise encode as multi-byte UTF-8 */
|
||||
t += utf8_encode_unichar(t, u);
|
||||
}
|
||||
|
||||
*t = 0;
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ size_t cescape_char(char c, char *buf);
|
||||
int cunescape(const char *s, UnescapeFlags flags, char **ret);
|
||||
int cunescape_length(const char *s, size_t length, UnescapeFlags flags, char **ret);
|
||||
int cunescape_length_with_prefix(const char *s, size_t length, const char *prefix, UnescapeFlags flags, char **ret);
|
||||
int cunescape_one(const char *p, size_t length, char *ret, uint32_t *ret_unicode);
|
||||
int cunescape_one(const char *p, size_t length, uint32_t *ret, bool *eight_bit);
|
||||
|
||||
char *xescape(const char *s, const char *bad);
|
||||
|
||||
|
||||
@@ -108,8 +108,9 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
|
||||
|
||||
if (flags & EXTRACT_CUNESCAPE) {
|
||||
uint32_t u;
|
||||
bool eight_bit = false;
|
||||
|
||||
r = cunescape_one(*p, (size_t) -1, &c, &u);
|
||||
r = cunescape_one(*p, (size_t) -1, &u, &eight_bit);
|
||||
if (r < 0) {
|
||||
if (flags & EXTRACT_CUNESCAPE_RELAX) {
|
||||
s[sz++] = '\\';
|
||||
@@ -119,10 +120,10 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
|
||||
} else {
|
||||
(*p) += r - 1;
|
||||
|
||||
if (c != 0)
|
||||
s[sz++] = c; /* normal explicit char */
|
||||
if (eight_bit)
|
||||
s[sz++] = u;
|
||||
else
|
||||
sz += utf8_encode_unichar(s + sz, u); /* unicode chars we'll encode as utf8 */
|
||||
sz += utf8_encode_unichar(s + sz, u);
|
||||
}
|
||||
} else
|
||||
s[sz++] = c;
|
||||
|
||||
+2
-2
@@ -165,7 +165,7 @@ int read_one_line_file(const char *fn, char **line) {
|
||||
if (!fgets(t, sizeof(t), f)) {
|
||||
|
||||
if (ferror(f))
|
||||
return errno ? -errno : -EIO;
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
|
||||
t[0] = 0;
|
||||
}
|
||||
@@ -1064,7 +1064,7 @@ int fflush_and_check(FILE *f) {
|
||||
fflush(f);
|
||||
|
||||
if (ferror(f))
|
||||
return errno ? -errno : -EIO;
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-1
@@ -481,7 +481,7 @@ int get_files_in_directory(const char *path, char ***list) {
|
||||
|
||||
errno = 0;
|
||||
de = readdir(d);
|
||||
if (!de && errno != 0)
|
||||
if (!de && errno > 0)
|
||||
return -errno;
|
||||
if (!de)
|
||||
break;
|
||||
|
||||
@@ -40,7 +40,7 @@ int glob_exists(const char *path) {
|
||||
if (k == GLOB_NOSPACE)
|
||||
return -ENOMEM;
|
||||
if (k != 0)
|
||||
return errno ? -errno : -EIO;
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
|
||||
return !strv_isempty(g.gl_pathv);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ int glob_extend(char ***strv, const char *path) {
|
||||
if (k == GLOB_NOSPACE)
|
||||
return -ENOMEM;
|
||||
if (k != 0)
|
||||
return errno ? -errno : -EIO;
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
if (strv_isempty(g.gl_pathv))
|
||||
return -ENOENT;
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ int in_addr_to_string(int family, const union in_addr_union *u, char **ret) {
|
||||
errno = 0;
|
||||
if (!inet_ntop(family, u, x, l)) {
|
||||
free(x);
|
||||
return errno ? -errno : -EINVAL;
|
||||
return errno > 0 ? -errno : -EINVAL;
|
||||
}
|
||||
|
||||
*ret = x;
|
||||
@@ -236,7 +236,7 @@ int in_addr_from_string(int family, const char *s, union in_addr_union *ret) {
|
||||
|
||||
errno = 0;
|
||||
if (inet_pton(family, s, ret) <= 0)
|
||||
return errno ? -errno : -EINVAL;
|
||||
return errno > 0 ? -errno : -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+11
-11
@@ -81,7 +81,7 @@ int parse_mode(const char *s, mode_t *ret) {
|
||||
|
||||
errno = 0;
|
||||
l = strtol(s, &x, 8);
|
||||
if (errno != 0)
|
||||
if (errno > 0)
|
||||
return -errno;
|
||||
if (!x || x == s || *x)
|
||||
return -EINVAL;
|
||||
@@ -176,7 +176,7 @@ int parse_size(const char *t, uint64_t base, uint64_t *size) {
|
||||
|
||||
errno = 0;
|
||||
l = strtoull(p, &e, 10);
|
||||
if (errno != 0)
|
||||
if (errno > 0)
|
||||
return -errno;
|
||||
if (e == p)
|
||||
return -EINVAL;
|
||||
@@ -192,7 +192,7 @@ int parse_size(const char *t, uint64_t base, uint64_t *size) {
|
||||
char *e2;
|
||||
|
||||
l2 = strtoull(e, &e2, 10);
|
||||
if (errno != 0)
|
||||
if (errno > 0)
|
||||
return -errno;
|
||||
|
||||
/* Ignore failure. E.g. 10.M is valid */
|
||||
@@ -330,7 +330,7 @@ int safe_atou(const char *s, unsigned *ret_u) {
|
||||
|
||||
errno = 0;
|
||||
l = strtoul(s, &x, 0);
|
||||
if (errno != 0)
|
||||
if (errno > 0)
|
||||
return -errno;
|
||||
if (!x || x == s || *x)
|
||||
return -EINVAL;
|
||||
@@ -352,7 +352,7 @@ int safe_atoi(const char *s, int *ret_i) {
|
||||
|
||||
errno = 0;
|
||||
l = strtol(s, &x, 0);
|
||||
if (errno != 0)
|
||||
if (errno > 0)
|
||||
return -errno;
|
||||
if (!x || x == s || *x)
|
||||
return -EINVAL;
|
||||
@@ -374,7 +374,7 @@ int safe_atollu(const char *s, long long unsigned *ret_llu) {
|
||||
|
||||
errno = 0;
|
||||
l = strtoull(s, &x, 0);
|
||||
if (errno != 0)
|
||||
if (errno > 0)
|
||||
return -errno;
|
||||
if (!x || x == s || *x)
|
||||
return -EINVAL;
|
||||
@@ -394,7 +394,7 @@ int safe_atolli(const char *s, long long int *ret_lli) {
|
||||
|
||||
errno = 0;
|
||||
l = strtoll(s, &x, 0);
|
||||
if (errno != 0)
|
||||
if (errno > 0)
|
||||
return -errno;
|
||||
if (!x || x == s || *x)
|
||||
return -EINVAL;
|
||||
@@ -414,7 +414,7 @@ int safe_atou8(const char *s, uint8_t *ret) {
|
||||
|
||||
errno = 0;
|
||||
l = strtoul(s, &x, 0);
|
||||
if (errno != 0)
|
||||
if (errno > 0)
|
||||
return -errno;
|
||||
if (!x || x == s || *x)
|
||||
return -EINVAL;
|
||||
@@ -438,7 +438,7 @@ int safe_atou16(const char *s, uint16_t *ret) {
|
||||
|
||||
errno = 0;
|
||||
l = strtoul(s, &x, 0);
|
||||
if (errno != 0)
|
||||
if (errno > 0)
|
||||
return -errno;
|
||||
if (!x || x == s || *x)
|
||||
return -EINVAL;
|
||||
@@ -460,7 +460,7 @@ int safe_atoi16(const char *s, int16_t *ret) {
|
||||
|
||||
errno = 0;
|
||||
l = strtol(s, &x, 0);
|
||||
if (errno != 0)
|
||||
if (errno > 0)
|
||||
return -errno;
|
||||
if (!x || x == s || *x)
|
||||
return -EINVAL;
|
||||
@@ -485,7 +485,7 @@ int safe_atod(const char *s, double *ret_d) {
|
||||
|
||||
errno = 0;
|
||||
d = strtod_l(s, &x, loc);
|
||||
if (errno != 0) {
|
||||
if (errno > 0) {
|
||||
freelocale(loc);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ int path_make_absolute_cwd(const char *p, char **ret) {
|
||||
|
||||
cwd = get_current_dir_name();
|
||||
if (!cwd)
|
||||
return -errno;
|
||||
return negative_errno();
|
||||
|
||||
c = strjoin(cwd, "/", p, NULL);
|
||||
}
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
|
||||
errno = 0;
|
||||
de = readdir(d);
|
||||
if (!de) {
|
||||
if (errno != 0 && ret == 0)
|
||||
if (errno > 0 && ret == 0)
|
||||
ret = -errno;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ int read_one_char(FILE *f, char *ret, usec_t t, bool *need_nl) {
|
||||
|
||||
errno = 0;
|
||||
if (!fgets(line, sizeof(line), f))
|
||||
return errno ? -errno : -EIO;
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
|
||||
truncate_nl(line);
|
||||
|
||||
@@ -212,7 +212,7 @@ int ask_string(char **ret, const char *text, ...) {
|
||||
|
||||
errno = 0;
|
||||
if (!fgets(line, sizeof(line), stdin))
|
||||
return errno ? -errno : -EIO;
|
||||
return errno > 0 ? -errno : -EIO;
|
||||
|
||||
if (!endswith(line, "\n"))
|
||||
putchar('\n');
|
||||
|
||||
@@ -68,7 +68,7 @@ int parse_uid(const char *s, uid_t *ret) {
|
||||
if (!uid_is_valid(uid))
|
||||
return -ENXIO; /* we return ENXIO instead of EINVAL
|
||||
* here, to make it easy to distuingish
|
||||
* invalid numeric uids invalid
|
||||
* invalid numeric uids from invalid
|
||||
* strings. */
|
||||
|
||||
if (ret)
|
||||
|
||||
+1
-1
@@ -513,7 +513,7 @@ int on_ac_power(void) {
|
||||
|
||||
errno = 0;
|
||||
de = readdir(d);
|
||||
if (!de && errno != 0)
|
||||
if (!de && errno > 0)
|
||||
return -errno;
|
||||
|
||||
if (!de)
|
||||
|
||||
Reference in New Issue
Block a user