[wiki] [sites] Removed memory-bug in json-patch for dmenu || C.J.Wagenius
commit 8d78c5d3a688850d00cdcef61f5fcc4f5ba2f0fd
Author: C.J.Wagenius <cjw_AT_voidptr.se>
Date: Tue Sep 24 15:12:14 2019 +0200
Removed memory-bug in json-patch for dmenu
diff --git a/tools.suckless.org/dmenu/patches/json/dmenu-json-4.9.diff b/tools.suckless.org/dmenu/patches/json/dmenu-json-4.9-r2.diff
similarity index 89%
rename from tools.suckless.org/dmenu/patches/json/dmenu-json-4.9.diff
rename to tools.suckless.org/dmenu/patches/json/dmenu-json-4.9-r2.diff
index 94db0d52..7a5a710e 100644
--- a/tools.suckless.org/dmenu/patches/json/dmenu-json-4.9.diff
+++ b/tools.suckless.org/dmenu/patches/json/dmenu-json-4.9-r2.diff
_AT_@ -1,14 +1,16 @@
diff --git a/config.mk b/config.mk
-index 0929b4a..6cb79e2 100644
+index 0929b4a..4627988 100644
--- a/config.mk
+++ b/config.mk
-_AT_@ -18,13 +18,17 @@ FREETYPEINC = /usr/include/freetype2
+_AT_@ -18,13 +18,19 @@ FREETYPEINC = /usr/include/freetype2
# OpenBSD (uncomment)
#FREETYPEINC = $(X11INC)/freetype2
+# jansson
+JANSSONINC = `pkg-config --cflags jansson`
+JANSSONLIBS = `pkg-config --libs jansson`
++# uncomment on RHEL for strcasecmp
++#EXTRAFLAGS=-D_GNU_SOURCE
+
# includes and libs
-INCS = -I$(X11INC) -I$(FREETYPEINC)
_AT_@ -17,14 +19,15 @@ index 0929b4a..6cb79e2 100644
+LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) $(JANSSONLIBS)
# flags
- CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS)
+-CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS)
-CFLAGS = -std=c99 -pedantic -Wall -Os $(INCS) $(CPPFLAGS)
++CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS) $(EXTRAFLAGS)
+CFLAGS = -std=c99 -pedantic -Wall -Os $(INCS) $(CPPFLAGS)
LDFLAGS = $(LIBS)
# compiler and linker
diff --git a/dmenu.c b/dmenu.c
-index 65f25ce..7b4cd66 100644
+index 65f25ce..58c1e23 100644
--- a/dmenu.c
+++ b/dmenu.c
_AT_@ -15,6 +15,7 @@
_AT_@ -101,11 +104,10 @@ index 65f25ce..7b4cd66 100644
if (!(ev->state & ControlMask)) {
cleanup();
exit(0);
-_AT_@ -518,33 +548,72 @@ paste(void)
- drawmenu();
+_AT_@ -519,32 +549,71 @@ paste(void)
}
-+static void
+ static void
+readjson(const char *path)
+{
+ json_error_t jerr;
_AT_@ -118,10 +120,9 @@ index 65f25ce..7b4cd66 100644
+listjson(json_t *obj)
+{
+ void *iter;
++ unsigned imax = 0;
+ unsigned tmpmax = 0;
+ struct item *item;
-+ struct item *longest = items;
-+
+
+ items_ln = 0;
+ iter = json_object_iter(obj);
_AT_@ -134,24 +135,25 @@ index 65f25ce..7b4cd66 100644
+ &tmpmax, NULL);
+ if (tmpmax > inputw) {
+ inputw = tmpmax;
-+ longest = item;
++ imax = items_ln - 1;
+ }
+ iter = json_object_iter_next(obj, iter);
+ }
+ if (items)
+ items[items_ln].text = NULL;
-+ inputw = items ? TEXTW(longest->text) : 0;
++ inputw = items ? TEXTW(items[imax].text) : 0;
+ lines = MIN(lines, items_ln - 1);
+}
+
- static void
++static void
readstdin(void)
{
char buf[sizeof text], *p;
- size_t i, imax = 0, size = 0;
+ size_t i;
++ unsigned int imax = 0;
unsigned int tmpmax = 0;
-+ struct item *item, *longest;
++ struct item *item;
/* read each line from stdin and add it to the item list */
for (i = 0; fgets(buf, sizeof buf, stdin); i++) {
_AT_@ -171,15 +173,14 @@ index 65f25ce..7b4cd66 100644
if (tmpmax > inputw) {
inputw = tmpmax;
- imax = i;
-+ longest = item;
++ imax = items_ln - 1;
}
}
if (items)
- items[i].text = NULL;
-- inputw = items ? TEXTW(items[imax].text) : 0;
-- lines = MIN(lines, i);
+ items[items_ln].text = NULL;
-+ inputw = items ? TEXTW(longest->text) : 0;
+ inputw = items ? TEXTW(items[imax].text) : 0;
+- lines = MIN(lines, i);
+ lines = MIN(lines, items_ln);
}
Received on Tue Sep 24 2019 - 15:13:50 CEST
This archive was generated by hypermail 2.3.0
: Tue Sep 24 2019 - 15:24:29 CEST