util: check asprintf return

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-11-10 10:35:53 +01:00
parent c13654f08d
commit 83eadb46cb
6 changed files with 23 additions and 27 deletions

View File

@ -19,7 +19,6 @@
*
*/
#define _GNU_SOURCE
#include <getopt.h>
#include <locale.h>

View File

@ -19,13 +19,8 @@
*
*/
/* asprintf */
#define _GNU_SOURCE
#include <glib.h>
#include <stdio.h>
#include "common/markup.h"
/** Callback to invoke when the opening tag of an element is seen.

View File

@ -21,7 +21,6 @@
*/
#include <stdarg.h>
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
#include <limits.h>

View File

@ -23,11 +23,15 @@
#ifndef AWESOME_COMMON_UTIL_H
#define AWESOME_COMMON_UTIL_H
/* asprintf */
#define _GNU_SOURCE
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdarg.h>
#include <assert.h>
#include <stdio.h>
#if !(defined (__FreeBSD__) || defined(__OpenBSD__))
#include <alloca.h>
@ -352,5 +356,11 @@ const char * name_func_rlookup(void *, const name_func_link_t *);
void a_exec(const char *);
char ** a_strsplit(const char *, ssize_t, char);
#define a_asprintf(strp, fmt, ...) \
do { \
if(asprintf(strp, fmt, ## __VA_ARGS__) < 0) \
abort(); \
} while(0)
#endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -19,10 +19,7 @@
*
*/
/* asprintf() */
#define _GNU_SOURCE
#include <stdio.h>
#include "common/util.h"
#include <xcb/xcb.h>
#include <xcb/xcb_atom.h>
@ -31,7 +28,6 @@
/* CURSORFONT */
#include <X11/Xlibint.h>
#include "common/util.h"
#include "common/xutil.h"
#include "common/atoms.h"
@ -319,14 +315,14 @@ xutil_error_init(const xcb_generic_error_t *e, xutil_error_t *err)
/* Extensions generally provide their own requests so we just
* store the request code */
if(err->request_code >= (sizeof(xutil_label_request) / sizeof(char *)))
asprintf(&err->request_label, "%d", err->request_code);
a_asprintf(&err->request_label, "%d", err->request_code);
else
err->request_label = a_strdup(xutil_label_request[err->request_code]);
/* Extensions may also define their own errors, so just store the
* error_code */
if(e->error_code >= (sizeof(xutil_label_error) / sizeof(char *)))
asprintf(&err->error_label, "%d", e->error_code);
a_asprintf(&err->error_label, "%d", e->error_code);
else
err->error_label = a_strdup(xutil_label_error[e->error_code]);

23
luaa.c
View File

@ -19,11 +19,9 @@
*
*/
/* asprintf */
#define _GNU_SOURCE
#include "common/util.h"
#include <errno.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
@ -31,7 +29,6 @@
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <ev.h>
@ -884,16 +881,16 @@ luaA_init(void)
if((dir = getenv("XDG_CONFIG_HOME")))
{
char *path;
asprintf(&path, "package.path = package.path .. \";%s/awesome/?.lua;%s/awesome/?/init.lua\"", dir, dir);
a_asprintf(&path, "package.path = package.path .. \";%s/awesome/?.lua;%s/awesome/?/init.lua\"", dir, dir);
luaA_dostring(globalconf.L, path);
p_delete(&path);
}
else
{
char *path, *homedir = getenv("HOME");
asprintf(&path,
"package.path = package.path .. \";%s" XDG_CONFIG_HOME_DEFAULT "/awesome/?.lua;%s" XDG_CONFIG_HOME_DEFAULT "/awesome/?/init.lua\"",
homedir, homedir);
a_asprintf(&path,
"package.path = package.path .. \";%s" XDG_CONFIG_HOME_DEFAULT "/awesome/?.lua;%s" XDG_CONFIG_HOME_DEFAULT "/awesome/?/init.lua\"",
homedir, homedir);
luaA_dostring(globalconf.L, path);
p_delete(&path);
}
@ -909,8 +906,8 @@ luaA_init(void)
for(buf = xdg_files; *buf; buf++)
{
char *confpath;
asprintf(&confpath, "package.path = package.path .. \";%s/awesome/?.lua;%s/awesome/?/init.lua\"",
*buf, *buf);
a_asprintf(&confpath, "package.path = package.path .. \";%s/awesome/?.lua;%s/awesome/?/init.lua\"",
*buf, *buf);
luaA_dostring(globalconf.L, confpath);
p_delete(&confpath);
}
@ -971,9 +968,9 @@ luaA_parserc(const char *confpatharg, bool run)
}
if((confdir = getenv("XDG_CONFIG_HOME")))
asprintf(&confpath, "%s" AWESOME_CONFIG_FILE, confdir);
a_asprintf(&confpath, "%s" AWESOME_CONFIG_FILE, confdir);
else
asprintf(&confpath, "%s" XDG_CONFIG_HOME_DEFAULT AWESOME_CONFIG_FILE, getenv("HOME"));
a_asprintf(&confpath, "%s" XDG_CONFIG_HOME_DEFAULT AWESOME_CONFIG_FILE, getenv("HOME"));
/* try to run XDG_CONFIG_HOME/awesome/rc.lua */
if(luaA_loadrc(confpath, run))
@ -996,7 +993,7 @@ luaA_parserc(const char *confpatharg, bool run)
for(buf = xdg_files; *buf && !ret; buf++)
{
asprintf(&confpath, "%s" AWESOME_CONFIG_FILE, *buf);
a_asprintf(&confpath, "%s" AWESOME_CONFIG_FILE, *buf);
if(luaA_loadrc(confpath, run))
{
ret = true;