This fixes warnings reported by -Wsign-compare compiler option.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Tomas Mraz <tmraz@fedoraproject.org>
/* There's some confusion in the documentation about what vsnprintf
* returns when the buffer overflows. Hmmm... */
len = vsnprintf(msg, sizeof(msg), fmt, args);
- if (len >= sizeof(msg) - 1)
+ if (len < 0) {
+ msg[0] = '\0';
+ strncat(msg, "(vsnprintf failed)", sizeof(msg));
+ return;
+ }
+ if ((size_t) len >= sizeof(msg) - 1)
strcpy(msg + sizeof(msg) - sizeof(truncated), truncated);
}
* This is not the most efficient, or elegant way of doing this.
*/
{
- int r, n;
+ int r;
+ unsigned int n;
regex_t crx;
va_list va;
char **substring;
regmatch_t *sub_offsets;
+
sub_offsets = malloc(sizeof(regmatch_t) * (n_sub + 1));
if (sub_offsets == NULL)
return -1;
dir = P_tmpdir;
len = snprintf(template, sizeof(template), "%s/$anacronXXXXXX", dir);
- if (len >= sizeof(template))
+ if (len < 0)
+ die_e("snprintf failed");
+ else if ((size_t) len >= sizeof(template))
die_e("TMPDIR too long");
fdout = mkstemp(template);
gethostname(hostname, MAXHOSTNAMELEN);
if (MailCmd[0] == '\0') {
- if (snprintf(mailcmd, sizeof mailcmd, MAILFMT, MAILARG, mailfrom)
- >= sizeof mailcmd) {
+ int len;
+
+ len = snprintf(mailcmd, sizeof mailcmd, MAILFMT, MAILARG, mailfrom);
+ if (len < 0) {
+ fprintf(stderr, "mailcmd snprintf failed\n");
+ (void) _exit(ERROR_EXIT);
+ }
+ if (sizeof mailcmd <= (size_t) len) {
fprintf(stderr, "mailcmd too long\n");
(void) _exit(ERROR_EXIT);
}
#include <ctype.h>
#include <errno.h>
+#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
while ((p = *envp++) != NULL) {
if (!(q = strchr(p, '=')))
continue;
- if ((q - p) == len && !strncmp(p, name, len))
+ if ((size_t)(q - p) == len && !strncmp(p, name, len))
return (q + 1);
}
return (NULL);