Fix should strictly follow the rule to return negative errno-style
error codes from functions, hence let's fix more "return -1"-style
lazinesses.
if (sendto(fd, packet, size, MSG_NOSIGNAL, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(socket_name)) < 0) {
log_error("Failed to send: %m");
if (sendto(fd, packet, size, MSG_NOSIGNAL, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(socket_name)) < 0) {
log_error("Failed to send: %m");
size_t i, j;
if (str == NULL || str_enc == NULL)
size_t i, j;
if (str == NULL || str_enc == NULL)
for (i = 0, j = 0; str[i] != '\0'; i++) {
int seqlen;
for (i = 0, j = 0; str[i] != '\0'; i++) {
int seqlen;
str_enc[j] = '\0';
return 0;
err:
str_enc[j] = '\0';
return 0;
err:
else if (s[i] >= 'A' && s[i] <= 'F')
id |= (s[i] - 'A' + 10) << (3 - i) * 4;
else
else if (s[i] >= 'A' && s[i] <= 'F')
id |= (s[i] - 'A' + 10) << (3 - i) * 4;
else
/* count of characters used to encode one unicode char */
static int utf8_encoded_expected_len(const char *str) {
/* count of characters used to encode one unicode char */
static int utf8_encoded_expected_len(const char *str) {
- unsigned char c = (unsigned char)str[0];
+ assert(str);
+
+ c = (unsigned char) str[0];
if (c < 0x80)
return 1;
if ((c & 0xe0) == 0xc0)
if (c < 0x80)
return 1;
if ((c & 0xe0) == 0xc0)
return 5;
if ((c & 0xfe) == 0xfc)
return 6;
return 5;
if ((c & 0xfe) == 0xfc)
return 6;
return 0;
}
/* decode one unicode char */
int utf8_encoded_to_unichar(const char *str) {
return 0;
}
/* decode one unicode char */
int utf8_encoded_to_unichar(const char *str) {
- int unichar;
- int len;
- int i;
+ int unichar, len, i;
+
+ assert(str);
len = utf8_encoded_expected_len(str);
len = utf8_encoded_expected_len(str);
switch (len) {
case 1:
return (int)str[0];
switch (len) {
case 1:
return (int)str[0];
unichar = (int)str[0] & 0x01;
break;
default:
unichar = (int)str[0] & 0x01;
break;
default:
}
for (i = 1; i < len; i++) {
if (((int)str[i] & 0xc0) != 0x80)
}
for (i = 1; i < len; i++) {
if (((int)str[i] & 0xc0) != 0x80)
unichar <<= 6;
unichar |= (int)str[i] & 0x3f;
}
unichar <<= 6;
unichar |= (int)str[i] & 0x3f;
}
assert(str);
for (p = (const uint8_t*) str; length;) {
assert(str);
for (p = (const uint8_t*) str; length;) {
- int encoded_len = utf8_encoded_valid_unichar((const char *)p);
- int val = utf8_encoded_to_unichar((const char*)p);
+ int encoded_len, val;
+
+ encoded_len = utf8_encoded_valid_unichar((const char *) p);
+ val = utf8_encoded_to_unichar((const char*) p);
- if (encoded_len < 0 || val < 0 || is_unicode_control(val) ||
+ if (encoded_len < 0 ||
+ val < 0 ||
+ is_unicode_control(val) ||
(!newline && val == '\n'))
return false;
(!newline && val == '\n'))
return false;
int len;
len = utf8_encoded_valid_unichar((const char *)p);
int len;
len = utf8_encoded_valid_unichar((const char *)p);
if (len < 0)
return NULL;
if (len < 0)
return NULL;
/* expected size used to encode one unicode char */
static int utf8_unichar_to_encoded_len(int unichar) {
/* expected size used to encode one unicode char */
static int utf8_unichar_to_encoded_len(int unichar) {
if (unichar < 0x80)
return 1;
if (unichar < 0x800)
if (unichar < 0x80)
return 1;
if (unichar < 0x800)
return 4;
if (unichar < 0x4000000)
return 5;
return 4;
if (unichar < 0x4000000)
return 5;
return 6;
}
/* validate one encoded unicode char and return its length */
int utf8_encoded_valid_unichar(const char *str) {
return 6;
}
/* validate one encoded unicode char and return its length */
int utf8_encoded_valid_unichar(const char *str) {
- int len;
- int unichar;
- int i;
+ int len, unichar, i;
+
+ assert(str);
len = utf8_encoded_expected_len(str);
if (len == 0)
len = utf8_encoded_expected_len(str);
if (len == 0)
/* ascii is valid */
if (len == 1)
/* ascii is valid */
if (len == 1)
/* check if expected encoded chars are available */
for (i = 0; i < len; i++)
if ((str[i] & 0x80) != 0x80)
/* check if expected encoded chars are available */
for (i = 0; i < len; i++)
if ((str[i] & 0x80) != 0x80)
unichar = utf8_encoded_to_unichar(str);
/* check if encoded length matches encoded value */
if (utf8_unichar_to_encoded_len(unichar) != len)
unichar = utf8_encoded_to_unichar(str);
/* check if encoded length matches encoded value */
if (utf8_unichar_to_encoded_len(unichar) != len)
/* check if value has valid range */
if (!is_unicode_valid(unichar))
/* check if value has valid range */
if (!is_unicode_valid(unichar))
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
}
char *hexmem(const void *p, size_t l) {
}
char *hexmem(const void *p, size_t l) {
if (c >= '0' && c <= '7')
return c - '0';
if (c >= '0' && c <= '7')
return c - '0';
if (c >= '0' && c <= '9')
return c - '0';
if (c >= '0' && c <= '9')
return c - '0';
}
char *cescape(const char *s) {
}
char *cescape(const char *s) {
if (signo > 0 && signo < _NSIG)
return signo;
}
if (signo > 0 && signo < _NSIG)
return signo;
}
}
bool kexec_loaded(void) {
}
bool kexec_loaded(void) {