Introduction
Introduction Statistics Contact Development Disclaimer Help
Added a util function estrdup() to check all memory allocations - svkbd - simpl…
git clone git://git.suckless.org/svkbd
Log
Files
Refs
README
LICENSE
---
commit f2322e9c0e5315e5dcc2c12b9296ae963a2a617d
parent 10024fc9637e4ae5f0fc55db95a079c05ce0d409
Author: Maarten van Gompel <[email protected]>
Date: Sat, 27 Mar 2021 17:57:28 +0100
Added a util function estrdup() to check all memory allocations
Diffstat:
M svkbd.c | 61 ++++++++++++++++++-----------…
1 file changed, 35 insertions(+), 26 deletions(-)
---
diff --git a/svkbd.c b/svkbd.c
@@ -11,6 +11,7 @@
#include <time.h>
#include <unistd.h>
#include <ctype.h>
+#include <err.h>
#include <X11/keysym.h>
#include <X11/keysymdef.h>
@@ -84,6 +85,8 @@ static void togglelayer();
static void unpress(Key *k, KeySym mod);
static void updatekeys();
static void printkey(Key *k, KeySym mod);
+static char *estrdup(const char *str);
+
/* variables */
static int screen;
@@ -135,6 +138,12 @@ Bool sigtermd = False;
static Key keys[KEYS] = { NULL };
static Key* layers[LAYERS];
+char * estrdup(const char *str) {
+ char * tmp = strdup(str);
+ if (tmp == NULL) errx(1, "strdup failed");
+ return tmp;
+}
+
void
motionnotify(XEvent *e)
{
@@ -703,57 +712,57 @@ readxresources(void) {
XrmValue xval;
if (XrmGetResource(xdb, "svkbd.font", "*", &type, &xval) && !f…
- fonts[0] = strdup(xval.addr);
+ fonts[0] = estrdup(xval.addr);
if (XrmGetResource(xdb, "svkbd.background", "*", &type, &xval)…
- colors[SchemeNorm][ColBg] = strdup(xval.addr);
+ colors[SchemeNorm][ColBg] = estrdup(xval.addr);
if (XrmGetResource(xdb, "svkbd.foreground", "*", &type, &xval)…
- colors[SchemeNorm][ColFg] = strdup(xval.addr);
+ colors[SchemeNorm][ColFg] = estrdup(xval.addr);
if (XrmGetResource(xdb, "svkbd.shiftforeground", "*", &type, &…
- colors[SchemeNormShift][ColFg] = strdup(xval.a…
+ colors[SchemeNormShift][ColFg] = estrdup(xval.…
if (XrmGetResource(xdb, "svkbd.shiftbackground", "*", &type, &…
- colors[SchemeNormShift][ColBg] = strdup(xval.a…
+ colors[SchemeNormShift][ColBg] = estrdup(xval.…
if (XrmGetResource(xdb, "svkbd.ABCforeground", "*", &type, &xv…
- colors[SchemeNormABC][ColFg] = strdup(xval.add…
+ colors[SchemeNormABC][ColFg] = estrdup(xval.ad…
if (XrmGetResource(xdb, "svkbd.ABCbackground", "*", &type, &xv…
- colors[SchemeNormABC][ColBg] = strdup(xval.add…
+ colors[SchemeNormABC][ColBg] = estrdup(xval.ad…
if (XrmGetResource(xdb, "svkbd.ABCshiftforeground", "*", &type…
- colors[SchemeNormShift][ColFg] = strdup(xval.a…
+ colors[SchemeNormShift][ColFg] = estrdup(xval.…
if (XrmGetResource(xdb, "svkbd.ABCshiftbackground", "*", &type…
- colors[SchemeNormShift][ColBg] = strdup(xval.a…
+ colors[SchemeNormShift][ColBg] = estrdup(xval.…
if (XrmGetResource(xdb, "svkbd.pressbackground", "*", &type, &…
- colors[SchemePress][ColBg] = strdup(xval.addr);
+ colors[SchemePress][ColBg] = estrdup(xval.addr…
if (XrmGetResource(xdb, "svkbd.pressforeground", "*", &type, &…
- colors[SchemePress][ColFg] = strdup(xval.addr);
+ colors[SchemePress][ColFg] = estrdup(xval.addr…
if (XrmGetResource(xdb, "svkbd.pressshiftbackground", "*", &ty…
- colors[SchemePressShift][ColBg] = strdup(xval.…
+ colors[SchemePressShift][ColBg] = estrdup(xval…
if (XrmGetResource(xdb, "svkbd.pressshiftforeground", "*", &ty…
- colors[SchemePressShift][ColFg] = strdup(xval.…
+ colors[SchemePressShift][ColFg] = estrdup(xval…
if (XrmGetResource(xdb, "svkbd.highlightbackground", "*", &typ…
- colors[SchemeHighlight][ColBg] = strdup(xval.a…
+ colors[SchemeHighlight][ColBg] = estrdup(xval.…
if (XrmGetResource(xdb, "svkbd.highlightforeground", "*", &typ…
- colors[SchemeHighlight][ColFg] = strdup(xval.a…
+ colors[SchemeHighlight][ColFg] = estrdup(xval.…
if (XrmGetResource(xdb, "svkbd.highlightshiftbackground", "*",…
- colors[SchemeHighlightShift][ColBg] = strdup(x…
+ colors[SchemeHighlightShift][ColBg] = estrdup(…
if (XrmGetResource(xdb, "svkbd.highlightshiftforeground", "*",…
- colors[SchemeHighlightShift][ColFg] = strdup(x…
+ colors[SchemeHighlightShift][ColFg] = estrdup(…
if (XrmGetResource(xdb, "svkbd.overlaybackground", "*", &type,…
- colors[SchemeOverlay][ColBg] = strdup(xval.add…
+ colors[SchemeOverlay][ColBg] = estrdup(xval.ad…
if (XrmGetResource(xdb, "svkbd.overlayforeground", "*", &type,…
- colors[SchemeOverlay][ColFg] = strdup(xval.add…
+ colors[SchemeOverlay][ColFg] = estrdup(xval.ad…
if (XrmGetResource(xdb, "svkbd.overlayshiftbackground", "*", &…
- colors[SchemeOverlayShift][ColBg] = strdup(xva…
+ colors[SchemeOverlayShift][ColBg] = estrdup(xv…
if (XrmGetResource(xdb, "svkbd.overlayshiftforeground", "*", &…
- colors[SchemeOverlayShift][ColFg] = strdup(xva…
+ colors[SchemeOverlayShift][ColFg] = estrdup(xv…
XrmDestroyDatabase(xdb);
@@ -797,11 +806,11 @@ setup(void)
/* Apply defaults to font and colors*/
if ( !fonts[0] )
- fonts[0] = strdup(defaultfonts[0]);
+ fonts[0] = estrdup(defaultfonts[0]);
for (i = 0; i < SchemeLast; ++i){
for (j = 0; j < 2; ++j){
if ( !colors[i][j] )
- colors[i][j] = strdup(defaultcolors[i][j]);
+ colors[i][j] = estrdup(defaultcolors[i][j]);
}
}
@@ -1122,7 +1131,7 @@ main(int argc, char *argv[])
enableoverlays = atoi(tmp);
}
if ((tmp = getenv("SVKBD_LAYERS"))) {
- if (!(layer_names_list = strdup(tmp)))
+ if (!(layer_names_list = estrdup(tmp)))
die("memory allocation error");
}
@@ -1158,7 +1167,7 @@ main(int argc, char *argv[])
wy = -1;
i++;
} else if (!strcmp(argv[i], "-fn")) { /* font or font set */
- fonts[0] = strdup(argv[++i]);
+ fonts[0] = estrdup(argv[++i]);
} else if (!strcmp(argv[i], "-D")) {
debug = 1;
} else if (!strcmp(argv[i], "-h")) {
@@ -1175,7 +1184,7 @@ main(int argc, char *argv[])
if (i >= argc - 1)
continue;
free(layer_names_list);
- if (!(layer_names_list = strdup(argv[++i])))
+ if (!(layer_names_list = estrdup(argv[++i])))
die("memory allocation error");
} else if (!strcmp(argv[i], "-s")) {
if (i >= argc - 1)
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.