Avoid unsigned integer underflow in drw_text()
[dwm.git] / util.c
blob8e26a51bd3a3b526d351c314a4916a2e64759a0e
1 /* See LICENSE file for copyright and license details. */
2 #include <errno.h>
3 #include <stdarg.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
8 #include "util.h"
10 void
11 die(const char *fmt, ...)
13 va_list ap;
14 int saved_errno;
16 saved_errno = errno;
18 va_start(ap, fmt);
19 vfprintf(stderr, fmt, ap);
20 va_end(ap);
22 if (fmt[0] && fmt[strlen(fmt)-1] == ':')
23 fprintf(stderr, " %s", strerror(saved_errno));
24 fputc('\n', stderr);
26 exit(1);
29 void *
30 ecalloc(size_t nmemb, size_t size)
32 void *p;
34 if (!(p = calloc(nmemb, size)))
35 die("calloc:");
36 return p;