here's the next iteration, taking carlos' notes into consideration,
plus some other stuff that came up (i always get distracted...)
please eye this (will turn it into a proper git patch once it's deemed
committable)
(most everything below refers to WINGs/ only)
- introduce the use of strlcat and strlcpy, bundle a copy for systems
not having it (XXX use libbsd on linuxes that have it)
- change wmalloc() to zero the allocated memory, clean up various
forms of zeroing throughout
- bits and pieces of whitespace mods where it really annoyed me
- wapplication.c:checkFile() returns NULL on several cases of NULLs in
its paramlist (this is not even an api change, unless you consider
segfault->sensible result an api change), which made it possible to
- massively simplify wapplication.c:WMPathForResourceOfType() (no more
redundant getenv()s)
- add wfilepanel.c:normalizePath() that removes redundant slashes from
file names (taken out of and completely rewritten from createDir())
- would you believe that 0xfff != 00777? (createDir():mkdir())
- wfilepanel.c:deleteFile() lost about a thousand pounds, while
gaining some correctness (why hand-roll strerror if we have one for free?)
- minimal changes to configure.ac (XXX figure this libbsd thing out...)
diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h
index 6849f52..bff5d14 100644
--- a/WINGs/WINGs/WUtil.h
+++ b/WINGs/WINGs/WUtil.h
@@ -875,7 +875,12 @@ extern int WCErrorCode;
/*-------------------------------------------------------------------------*/
-
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char *, const char *, size_t);
+#endif
+#ifndef HAVE_STRLCAT
+size_t strlcat(char *, const char *, size_t);
+#endif
#ifdef __cplusplus
}
diff --git a/WINGs/bagtree.c b/WINGs/bagtree.c
index a37c2d4..33830b3 100644
--- a/WINGs/bagtree.c
+++ b/WINGs/bagtree.c
@@ -359,10 +359,7 @@ WMBag *WMCreateTreeBagWithDestructor(WMFreeDataProc *
destructor)
bag = wmalloc(sizeof(WMBag));
- memset(bag, 0, sizeof(WMBag));
-
bag->nil = wmalloc(sizeof(W_Node));
- memset(bag->nil, 0, sizeof(W_Node));
bag->nil->left = bag->nil->right = bag->nil->parent = bag->nil;
bag->nil->index = WBNotFound;
diff --git a/WINGs/dragsource.c b/WINGs/dragsource.c
index eea0ef5..c1ea68a 100644
--- a/WINGs/dragsource.c
+++ b/WINGs/dragsource.c
@@ -478,7 +478,7 @@ static void registerDescriptionList(WMScreen * scr, WMView
* view, WMArray * ope
/* size of XA_STRING info */
for (i = 0; i < count; i++) {
- size +=
strlen(WMGetDragOperationItemText(WMGetFromArray(operationArray, i))) + 1;
/* +1 = +NULL */
+ size +=
strlen(WMGetDragOperationItemText(WMGetFromArray(operationArray, i))) + 1 /*
NULL */;
}
/* create text list */
diff --git a/WINGs/findfile.c b/WINGs/findfile.c
index 9aad1d7..1ead09d 100644
--- a/WINGs/findfile.c
+++ b/WINGs/findfile.c
@@ -84,9 +84,8 @@ char *wexpandpath(char *path)
path++;
if (*path == '/' || *path == 0) {
home = wgethomedir();
- if (strlen(home) > PATH_MAX)
+ if (strlcpy(buffer, home, sizeof(buffer)) >=
sizeof(buffer))
goto error;
- strcat(buffer, home);
} else {
int j;
j = 0;
@@ -98,9 +97,8 @@ char *wexpandpath(char *path)
path++;
}
home = getuserhomedir(buffer2);
- if (!home || strlen(home) > PATH_MAX)
+ if (!home || strlcpy(buffer, home, sizeof(buffer)) >=
sizeof(buffer))
goto error;
- strcat(buffer, home);
}
}
@@ -131,17 +129,20 @@ char *wexpandpath(char *path)
if ((i += strlen(buffer2) + 2) >
PATH_MAX)
goto error;
buffer[i] = 0;
- strcat(buffer, "$(");
- strcat(buffer, buffer2);
+ if (strlcat(buffer, "$(",
sizeof(buffer)) >= sizeof(buffer) ||
+ strlcat(buffer, buffer2,
sizeof(buffer)) >= sizeof(buffer))
+ goto error;
if (*(path-1)==')') {
if (++i > PATH_MAX)
goto error;
- strcat(buffer, ")");
+ if (strlcat(buffer, ")",
sizeof(buffer)) >= sizeof(buffer))
+ goto error;
}
} else {
if ((i += strlen(tmp)) > PATH_MAX)
goto error;
- strcat(buffer, tmp);
+ if (strlcat(buffer, tmp,
sizeof(buffer)) >= sizeof(buffer))
+ goto error;
}
} else {
while (*path != 0 && *path != '/') {
@@ -154,12 +155,14 @@ char *wexpandpath(char *path)
if (!tmp) {
if ((i += strlen(buffer2) + 1) >
PATH_MAX)
goto error;
- strcat(buffer, "$");
- strcat(buffer, buffer2);
+ if (strlcat(buffer, "$",
sizeof(buffer)) >= sizeof(buffer) ||
+ strlcat(buffer, buffer2,
sizeof(buffer)) >= sizeof(buffer))
+ goto error;
} else {
if ((i += strlen(tmp)) > PATH_MAX)
goto error;
- strcat(buffer, tmp);
+ if (strlcat(buffer, tmp,
sizeof(buffer)) >= sizeof(buffer))
+ goto error;
}
}
} else {
@@ -176,8 +179,7 @@ char *wexpandpath(char *path)
error:
errno = ENAMETOOLONG;
wsyserror(_("could not expand %s"), origpath);
- /* FIXME: too many functions handle a return value of NULL incorrectly
*/
- exit(1);
+ return NULL;
}
/* return address of next char != tok or end of string whichever comes first */
@@ -251,9 +253,16 @@ char *wfindfile(char *paths, char *file)
path = wmalloc(len + flen + 2);
path = memcpy(path, tmp, len);
path[len] = 0;
- if (path[len - 1] != '/')
- strcat(path, "/");
- strcat(path, file);
+ if (path[len - 1] != '/') {
+ if (strlcat(path, "/", len + flen + 2) >= len + flen +
2) {
+ wfree(path);
+ return NULL;
+ }
+ }
+ if (strlcat(path, file, len + flen + 2) >= len + flen + 2) {
+ wfree(path);
+ return NULL;
+ }
fullpath = wexpandpath(path);
wfree(path);
if (fullpath) {
@@ -301,8 +310,11 @@ char *wfindfileinlist(char **path_list, char *file)
path = wmalloc(len + flen + 2);
path = memcpy(path, path_list[i], len);
path[len] = 0;
- strcat(path, "/");
- strcat(path, file);
+ if (strlcat(path, "/", len + flen + 2) >= len + flen + 2 ||
+ strlcat(path, file, len + flen + 2) >= len + flen + 2) {
+ wfree(path);
+ return NULL;
+ }
/* expand tilde */
fullpath = wexpandpath(path);
wfree(path);
@@ -358,8 +370,11 @@ char *wfindfileinarray(WMPropList * array, char *file)
path = wmalloc(len + flen + 2);
path = memcpy(path, p, len);
path[len] = 0;
- strcat(path, "/");
- strcat(path, file);
+ if (strlcat(path, "/", len + flen + 2) >= len + flen + 2 ||
+ strlcat(path, file, len + flen + 2) >= len + flen + 2) {
+ wfree(path);
+ return NULL;
+ }
/* expand tilde */
fullpath = wexpandpath(path);
wfree(path);
diff --git a/WINGs/hashtable.c b/WINGs/hashtable.c
index a85f0ee..d5ed3c9 100644
--- a/WINGs/hashtable.c
+++ b/WINGs/hashtable.c
@@ -81,7 +81,6 @@ static void rebuildTable(WMHashTable * table)
newSize = table->size * 2;
table->table = wmalloc(sizeof(char *) * newSize);
- memset(table->table, 0, sizeof(char *) * newSize);
table->size = newSize;
for (i = 0; i < oldSize; i++) {
@@ -99,14 +98,9 @@ WMHashTable *WMCreateHashTable(WMHashTableCallbacks
callbacks)
HashTable *table;
table = wmalloc(sizeof(HashTable));
- memset(table, 0, sizeof(HashTable));
-
table->callbacks = callbacks;
-
table->size = INITIAL_CAPACITY;
-
table->table = wmalloc(sizeof(HashItem *) * table->size);
- memset(table->table, 0, sizeof(HashItem *) * table->size);
return table;
}
diff --git a/WINGs/memory.c b/WINGs/memory.c
index 9d770b0..bb6df5c 100644
--- a/WINGs/memory.c
+++ b/WINGs/memory.c
@@ -95,6 +95,7 @@ void *wmalloc(size_t size)
}
}
}
+ memset(tmp, 0, size);
return tmp;
}
diff --git a/WINGs/notification.c b/WINGs/notification.c
index 3febb2c..5d0c802 100644
--- a/WINGs/notification.c
+++ b/WINGs/notification.c
@@ -35,11 +35,9 @@ WMNotification *WMCreateNotification(const char *name, void
*object, void *clien
Notification *nPtr;
nPtr = wmalloc(sizeof(Notification));
-
nPtr->name = name;
nPtr->object = object;
nPtr->clientData = clientData;
-
nPtr->refCount = 1;
return nPtr;
@@ -89,11 +87,9 @@ static NotificationCenter *notificationCenter = NULL;
void W_InitNotificationCenter(void)
{
notificationCenter = wmalloc(sizeof(NotificationCenter));
-
notificationCenter->nameTable =
WMCreateHashTable(WMStringPointerHashCallbacks);
notificationCenter->objectTable = WMCreateHashTable(WMIntHashCallbacks);
notificationCenter->nilList = NULL;
-
notificationCenter->observerTable =
WMCreateHashTable(WMIntHashCallbacks);
}
@@ -366,7 +362,6 @@ WMNotificationQueue *WMCreateNotificationQueue(void)
NotificationQueue *queue;
queue = wmalloc(sizeof(NotificationQueue));
-
queue->asapQueue = WMCreateArrayWithDestructor(8, (WMFreeDataProc *)
WMReleaseNotification);
queue->idleQueue = WMCreateArrayWithDestructor(8, (WMFreeDataProc *)
WMReleaseNotification);
queue->next = notificationQueueList;
diff --git a/WINGs/proplist.c b/WINGs/proplist.c
index b6cc1ab..593112f 100644
--- a/WINGs/proplist.c
+++ b/WINGs/proplist.c
@@ -891,7 +891,6 @@ WMPropList *WMCreatePLString(char *str)
wassertrv(str != NULL, NULL);
plist = (WMPropList *) wmalloc(sizeof(W_PropList));
-
plist->type = WPLString;
plist->d.string = wstrdup(str);
plist->retainCount = 1;
@@ -906,7 +905,6 @@ WMPropList *WMCreatePLData(WMData * data)
wassertrv(data != NULL, NULL);
plist = (WMPropList *) wmalloc(sizeof(W_PropList));
-
plist->type = WPLData;
plist->d.data = WMRetainData(data);
plist->retainCount = 1;
@@ -921,7 +919,6 @@ WMPropList *WMCreatePLDataWithBytes(unsigned char *bytes,
unsigned int length)
wassertrv(bytes != NULL, NULL);
plist = (WMPropList *) wmalloc(sizeof(W_PropList));
-
plist->type = WPLData;
plist->d.data = WMCreateDataWithBytes(bytes, length);
plist->retainCount = 1;
@@ -936,7 +933,6 @@ WMPropList *WMCreatePLDataWithBytesNoCopy(unsigned char
*bytes, unsigned int len
wassertrv(bytes != NULL, NULL);
plist = (WMPropList *) wmalloc(sizeof(W_PropList));
-
plist->type = WPLData;
plist->d.data = WMCreateDataWithBytesNoCopy(bytes, length, destructor);
plist->retainCount = 1;
diff --git a/WINGs/selection.c b/WINGs/selection.c
index ce93d22..21d1871 100644
--- a/WINGs/selection.c
+++ b/WINGs/selection.c
@@ -341,13 +341,11 @@ Bool WMCreateSelectionHandler(WMView * view, Atom
selection, Time timestamp, WMS
/*//printf("created selection handler for %d\n",
W_VIEW_DRAWABLE(view)); */
handler = wmalloc(sizeof(SelectionHandler));
-
handler->view = view;
handler->selection = selection;
handler->timestamp = timestamp;
handler->procs = *procs;
handler->data = cdata;
- memset(&handler->flags, 0, sizeof(handler->flags));
if (selHandlers == NULL) {
selHandlers = WMCreateArrayWithDestructor(4, wfree);
@@ -373,14 +371,12 @@ WMRequestSelection(WMView * view, Atom selection, Atom
target, Time timestamp,
}
handler = wmalloc(sizeof(SelectionCallback));
-
handler->view = view;
handler->selection = selection;
handler->target = target;
handler->timestamp = timestamp;
handler->callback = callback;
handler->data = cdata;
- memset(&handler->flags, 0, sizeof(handler->flags));
if (selCallbacks == NULL) {
selCallbacks = WMCreateArrayWithDestructor(4, wfree);
diff --git a/WINGs/string.c b/WINGs/string.c
index d4c426d..674fe1c 100644
--- a/WINGs/string.c
+++ b/WINGs/string.c
@@ -41,7 +41,6 @@ char *wtokennext(char *word, char **next)
ptr = word;
state = 0;
- *t = 0;
while (1) {
if (*ptr == 0)
ctype = PRC_EOS;
@@ -121,7 +120,6 @@ char *wtokenjoin(char **list, int count)
flat_string = wmalloc(j + count + 1);
- *flat_string = 0;
for (i = 0; i < count; i++) {
if (list[i] != NULL && list[i][0] != 0) {
if (i > 0)
@@ -184,29 +182,144 @@ char *wstrndup(const char *str, size_t len)
char *wstrconcat(char *str1, char *str2)
{
char *str;
+ size_t slen;
if (!str1)
return wstrdup(str2);
else if (!str2)
return wstrdup(str1);
- str = wmalloc(strlen(str1) + strlen(str2) + 1);
- strcpy(str, str1);
- strcat(str, str2);
+ slen = strlen(str1) + strlen(str2) + 1;
+ str = wmalloc(slen);
+ if (strlcpy(str, str1, slen) >= slen ||
+ strlcat(str, str2, slen) >= slen) {
+ wfree(str);
+ return NULL;
+ }
return str;
}
char *wstrappend(char *dst, char *src)
{
+ size_t slen;
+
if (!dst)
return wstrdup(src);
else if (!src || *src == 0)
return dst;
- dst = wrealloc(dst, strlen(dst) + strlen(src) + 1);
- strcat(dst, src);
-
+ slen = strlen(dst) + strlen(src) + 1;
+ dst = wrealloc(dst, slen);
+ if (strlcat(dst, src, slen) >= slen)
+ return NULL;
return dst;
}
+#ifndef HAVE_STRLCAT
+/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
+
+/*
+ * Copyright (c) 1998 Todd C. Miller <[email protected]>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Appends src to string dst of size siz (unlike strncat, siz is the
+ * full size of dst, not space left). At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
+ * Returns strlen(src) + MIN(siz, strlen(initial dst)).
+ * If retval >= siz, truncation occurred.
+ */
+size_t
+strlcat(char *dst, const char *src, size_t siz)
+{
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
+ size_t dlen;
+
+ /* Find the end of dst and adjust bytes left but don't go past end */
+ while (n-- != 0 && *d != '\0')
+ d++;
+ dlen = d - dst;
+ n = siz - dlen;
+
+ if (n == 0)
+ return(dlen + strlen(s));
+ while (*s != '\0') {
+ if (n != 1) {
+ *d++ = *s;
+ n--;
+ }
+ s++;
+ }
+ *d = '\0';
+
+ return(dlen + (s - src)); /* count does not include NUL */
+}
+#endif /* HAVE_STRLCAT */
+
+#ifndef HAVE_STRLCPY
+
+/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
+
+/*
+ * Copyright (c) 1998 Todd C. Miller <[email protected]>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Copy src to string dst of size siz. At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz == 0).
+ * Returns strlen(src); if retval >= siz, truncation occurred.
+ */
+size_t
+strlcpy(char *dst, const char *src, size_t siz)
+{
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0) {
+ while (--n != 0) {
+ if ((*d++ = *s++) == '\0')
+ break;
+ }
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return(s - src - 1); /* count does not include NUL */
+}
+#endif /* HAVE_STRLCPY */
+
diff --git a/WINGs/tree.c b/WINGs/tree.c
index 45c1497..875d46d 100644
--- a/WINGs/tree.c
+++ b/WINGs/tree.c
@@ -40,10 +40,7 @@ WMTreeNode *WMCreateTreeNodeWithDestructor(void *data,
WMFreeDataProc * destruct
WMTreeNode *aNode;
aNode = (WMTreeNode *) wmalloc(sizeof(W_TreeNode));
- memset(aNode, 0, sizeof(W_TreeNode));
-
aNode->destructor = destructor;
-
aNode->data = data;
aNode->parent = NULL;
aNode->depth = 0;
diff --git a/WINGs/userdefaults.c b/WINGs/userdefaults.c
index ee3a3b7..f9572a1 100644
--- a/WINGs/userdefaults.c
+++ b/WINGs/userdefaults.c
@@ -60,10 +60,16 @@ char *wusergnusteppath()
strcpy(path, gspath);
wfree(gspath);
} else {
- pathlen = strlen(wgethomedir()) + 10;
+ char *h = wgethomedir();
+ if (!h)
+ return NULL;
+ pathlen = strlen(h) + 8 /* /GNUstep */ + 1;
path = wmalloc(pathlen);
- strcpy(path, wgethomedir());
- strcat(path, "/GNUstep");
+ if (strlcpy(path, h, pathlen) >= pathlen ||
+ strlcat(path, "/GNUstep", pathlen) >= pathlen) {
+ wfree(path);
+ return NULL;
+ }
}
}
@@ -263,10 +269,7 @@ WMUserDefaults *WMGetStandardUserDefaults(void)
/* we didn't found the database we are looking for. Go read it. */
defaults = wmalloc(sizeof(WMUserDefaults));
- memset(defaults, 0, sizeof(WMUserDefaults));
-
defaults->defaults = WMCreatePLDictionary(NULL, NULL);
-
defaults->searchList = wmalloc(sizeof(WMPropList *) * 3);
/* application domain */
@@ -355,12 +358,9 @@ WMUserDefaults *WMGetDefaultsFromPath(char *path)
}
}
- /* we didn't found the database we are looking for. Go read it. */
+ /* we didn't found the database we are looking for. Go read it. XXX:
wtf?*/
defaults = wmalloc(sizeof(WMUserDefaults));
- memset(defaults, 0, sizeof(WMUserDefaults));
-
defaults->defaults = WMCreatePLDictionary(NULL, NULL);
-
defaults->searchList = wmalloc(sizeof(WMPropList *) * 2);
/* the domain we want, go in the first position */
diff --git a/WINGs/wapplication.c b/WINGs/wapplication.c
index 620e378..0fdd40a 100644
--- a/WINGs/wapplication.c
+++ b/WINGs/wapplication.c
@@ -65,39 +65,54 @@ static char *checkFile(char *path, char *folder, char *ext,
char *resource)
{
char *ret;
int extralen;
+ size_t slen;
- extralen = (ext ? strlen(ext) : 0) + (folder ? strlen(folder) : 0) + 4;
- ret = wmalloc(strlen(path) + strlen(resource) + extralen + 8);
- strcpy(ret, path);
- if (folder) {
- strcat(ret, "/");
- strcat(ret, folder);
- }
- if (ext) {
- strcat(ret, "/");
- strcat(ret, ext);
- }
- strcat(ret, "/");
- strcat(ret, resource);
+ if (!path || !resource)
+ return NULL;
- if (access(ret, F_OK) != 0) {
- wfree(ret);
- ret = NULL;
- }
+ extralen = (ext ? strlen(ext) + 1 : 0) + (folder ? strlen(folder) + 1 :
0) + 1;
+ slen = strlen(path) + strlen(resource) + 1 + extralen;
+ ret = wmalloc(slen);
+
+ if (strlcpy(ret, path, slen) >= slen)
+ goto error;
+
+ if (folder &&
+ (strlcat(ret, "/", slen) >= slen ||
+ strlcat(ret, folder, slen) >= slen))
+ goto error;
+
+ if (ext &&
+ (strlcat(ret, "/", slen) >= slen ||
+ strlcat(ret, ext, slen) >= slen))
+ goto error;
+
+ if (strlcat(ret, "/", slen) >= slen ||
+ strlcat(ret, resource, slen) >= slen)
+ goto error;
+
+ if (access(ret, F_OK) != 0)
+ goto error;
return ret;
+error:
+ if (ret)
+ wfree(ret);
+ return NULL;
}
char *WMPathForResourceOfType(char *resource, char *ext)
{
- char *path = NULL;
- char *tmp, *appdir;
+ char *path, *tmp, *appdir;
int i;
+ size_t slen;
+
+ path = tmp = appdir = NULL;
/*
* Paths are searched in this order:
* - resourcePath/ext
- * - argv[0]/ext
+ * - dirname(argv[0])/ext
* - GNUSTEP_USER_ROOT/Applications/ApplicationName.app/ext
* - ~/GNUstep/Applications/ApplicationName.app/ext
* - GNUSTEP_LOCAL_ROOT/Applications/ApplicationName.app/ext
@@ -106,11 +121,9 @@ char *WMPathForResourceOfType(char *resource, char *ext)
* - /usr/GNUstep/Applications/ApplicationName.app/ext
*/
- if (WMApplication.resourcePath) {
- path = checkFile(WMApplication.resourcePath, NULL, ext,
resource);
- if (path)
- return path;
- }
+ path = checkFile(WMApplication.resourcePath, NULL, ext, resource);
+ if (path)
+ goto out;
if (WMApplication.argv[0]) {
tmp = wstrdup(WMApplication.argv[0]);
@@ -128,53 +141,38 @@ char *WMPathForResourceOfType(char *resource, char *ext)
return path;
}
- appdir = wmalloc(strlen(WMApplication.applicationName) + 20);
- sprintf(appdir, "Applications/%s.app", WMApplication.applicationName);
+ slen = strlen(WMApplication.applicationName) +
sizeof("Applications/.app");
+ appdir = wmalloc(slen);
+ if (snprintf(appdir, slen, "Applications/%s.app",
WMApplication.applicationName) >= slen)
+ goto out;
- if (getenv("GNUSTEP_USER_ROOT")) {
- path = checkFile(getenv("GNUSTEP_USER_ROOT"), appdir, ext,
resource);
- if (path) {
- wfree(appdir);
- return path;
- }
- }
+ path = checkFile(getenv("GNUSTEP_USER_ROOT"), appdir, ext, resource);
+ if (path)
+ goto out;
- tmp = wusergnusteppath();
- if (tmp) {
- path = checkFile(tmp, appdir, ext, resource);
- if (path) {
- wfree(appdir);
- return path;
- }
- }
+ path = checkFile(wusergnusteppath(), appdir, ext, resource);
+ if (path)
+ goto out;
- if (getenv("GNUSTEP_LOCAL_ROOT")) {
- path = checkFile(getenv("GNUSTEP_LOCAL_ROOT"), appdir, ext,
resource);
- if (path) {
- wfree(appdir);
- return path;
- }
- }
+ path = checkFile(getenv("GNUSTEP_LOCAL_ROOT"), appdir, ext, resource);
+ if (path)
+ goto out;
path = checkFile("/usr/local/GNUstep", appdir, ext, resource);
- if (path) {
- wfree(appdir);
- return path;
- }
+ if (path)
+ goto out;
- if (getenv("GNUSTEP_SYSTEM_ROOT")) {
- path = checkFile(getenv("GNUSTEP_SYSTEM_ROOT"), appdir, ext,
resource);
- if (path) {
- wfree(appdir);
- return path;
- }
- }
+ path = checkFile(getenv("GNUSTEP_SYSTEM_ROOT"), appdir, ext, resource);
+ if (path)
+ goto out;
- path = checkFile("/usr/GNUstep", appdir, ext, resource);
- if (path) {
+ path = checkFile("/usr/GNUstep", appdir, ext, resource); /* falls
through */
+
+out:
+ if (tmp)
+ wfree(tmp);
+ if (appdir)
wfree(appdir);
- return path;
- }
- return NULL;
+ return path;
}
diff --git a/WINGs/wballoon.c b/WINGs/wballoon.c
index 1b33a89..17028d0 100644
--- a/WINGs/wballoon.c
+++ b/WINGs/wballoon.c
@@ -50,28 +50,23 @@ struct W_Balloon *W_CreateBalloon(WMScreen * scr)
Balloon *bPtr;
bPtr = wmalloc(sizeof(Balloon));
- memset(bPtr, 0, sizeof(Balloon));
-
bPtr->view = W_CreateUnmanagedTopView(scr);
+
if (!bPtr->view) {
wfree(bPtr);
return NULL;
}
- bPtr->view->self = bPtr;
+ bPtr->view->self = bPtr;
bPtr->textColor = WMRetainColor(bPtr->view->screen->black);
-
- WMCreateEventHandler(bPtr->view, StructureNotifyMask, handleEvents,
bPtr);
-
- W_ResizeView(bPtr->view, DEFAULT_WIDTH, DEFAULT_HEIGHT);
bPtr->flags.alignment = DEFAULT_ALIGNMENT;
-
bPtr->table = WMCreateHashTable(WMIntHashCallbacks);
-
bPtr->delay = DEFAULT_DELAY;
-
bPtr->flags.enabled = 1;
+ WMCreateEventHandler(bPtr->view, StructureNotifyMask, handleEvents,
bPtr);
+ W_ResizeView(bPtr->view, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+
return bPtr;
}
diff --git a/WINGs/wbox.c b/WINGs/wbox.c
index 2c7d949..3aaaade 100644
--- a/WINGs/wbox.c
+++ b/WINGs/wbox.c
@@ -44,23 +44,17 @@ WMBox *WMCreateBox(WMWidget * parent)
Box *bPtr;
bPtr = wmalloc(sizeof(Box));
- memset(bPtr, 0, sizeof(Box));
-
bPtr->widgetClass = WC_Box;
-
bPtr->view = W_CreateView(W_VIEW(parent));
if (!bPtr->view) {
wfree(bPtr);
return NULL;
}
bPtr->view->self = bPtr;
-
bPtr->view->delegate = &delegate;
-
bPtr->subviews = WMCreateArrayWithDestructor(2, wfree);
WMCreateEventHandler(bPtr->view, StructureNotifyMask, handleEvents,
bPtr);
-
WMResizeWidget(bPtr, DEFAULT_WIDTH, DEFAULT_HEIGHT);
return bPtr;
diff --git a/WINGs/wbrowser.c b/WINGs/wbrowser.c
index b539543..6048b4f 100644
--- a/WINGs/wbrowser.c
+++ b/WINGs/wbrowser.c
@@ -95,25 +95,18 @@ WMBrowser *WMCreateBrowser(WMWidget * parent)
wassertrv(parent, NULL);
bPtr = wmalloc(sizeof(WMBrowser));
- memset(bPtr, 0, sizeof(WMBrowser));
-
bPtr->widgetClass = WC_Browser;
-
bPtr->view = W_CreateView(W_VIEW(parent));
if (!bPtr->view) {
wfree(bPtr);
return NULL;
}
bPtr->view->self = bPtr;
-
bPtr->view->delegate = &_BrowserViewDelegate;
-
WMCreateEventHandler(bPtr->view, ExposureMask | StructureNotifyMask
| ClientMessageMask, handleEvents, bPtr);
-
/* default configuration */
bPtr->flags.hasScroller = DEFAULT_HAS_SCROLLER;
-
bPtr->titleHeight = DEFAULT_TITLE_HEIGHT;
bPtr->flags.isTitled = DEFAULT_IS_TITLED;
bPtr->maxVisibleColumns = DEFAULT_MAX_VISIBLE_COLUMNS;
@@ -121,15 +114,12 @@ WMBrowser *WMCreateBrowser(WMWidget * parent)
WMResizeWidget(bPtr, DEFAULT_WIDTH, DEFAULT_HEIGHT);
bPtr->pathSeparator = wstrdup(DEFAULT_SEPARATOR);
-
if (bPtr->flags.hasScroller)
setupScroller(bPtr);
-
for (i = 0; i < bPtr->maxVisibleColumns; i++) {
WMAddBrowserColumn(bPtr);
}
bPtr->usedColumnCount = 0;
-
bPtr->selectedColumn = -1;
return bPtr;
@@ -690,6 +680,7 @@ char *WMGetBrowserPathToColumn(WMBrowser * bPtr, int column)
{
int i, size;
char *path;
+ size_t slen;
WMListItem *item;
if (column >= bPtr->usedColumnCount)
@@ -709,15 +700,20 @@ char *WMGetBrowserPathToColumn(WMBrowser * bPtr, int
column)
}
/* get the path */
- path = wmalloc(size + (column + 1) * strlen(bPtr->pathSeparator) + 1);
- /* ignore first / */
- *path = 0;
+ slen = size + (column + 1) * strlen(bPtr->pathSeparator) + 1;
+ path = wmalloc(slen);
for (i = 0; i <= column; i++) {
- strcat(path, bPtr->pathSeparator);
+ if (strlcat(path, bPtr->pathSeparator, slen) >= slen) {
+ wfree(path);
+ return NULL;
+ }
item = WMGetListSelectedItem(bPtr->columns[i]);
if (!item)
break;
- strcat(path, item->text);
+ if (strlcat(path, item->text, slen) >= slen) {
+ wfree(path);
+ return NULL;
+ }
}
return path;
@@ -727,6 +723,7 @@ WMArray *WMGetBrowserPaths(WMBrowser * bPtr)
{
int column, i, k, size, selNo;
char *path;
+ size_t slen;
WMListItem *item, *lastItem;
WMArray *paths, *items;
@@ -761,19 +758,25 @@ WMArray *WMGetBrowserPaths(WMBrowser * bPtr)
for (k = 0; k < selNo; k++) {
/* get the path */
lastItem = WMGetFromArray(items, k);
- path = wmalloc(size + (lastItem != NULL ?
strlen(lastItem->text) : 0));
- /* ignore first / */
- *path = 0;
+ slen = size + (lastItem != NULL ? strlen(lastItem->text) : 0);
+ path = wmalloc(slen);
for (i = 0; i <= column; i++) {
- strcat(path, bPtr->pathSeparator);
- if (i == column) {
+ if (strlcat(path, bPtr->pathSeparator, slen) >= slen) {
+ wfree(path);
+ return NULL;
+ }
+ if (i == column)
item = lastItem;
- } else {
+ else
item = WMGetListSelectedItem(bPtr->columns[i]);
- }
+
if (!item)
break;
- strcat(path, item->text);
+
+ if (strlcat(path, item->text, slen) >= slen) {
+ wfree(path);
+ return NULL;
+ }
}
WMAddToArray(paths, path);
}
@@ -1102,23 +1105,39 @@ static void destroyBrowser(WMBrowser * bPtr)
static char *createTruncatedString(WMFont * font, char *text, int *textLen,
int width)
{
- int dLen = WMWidthOfString(font, ".", 1);
- char *textBuf = (char *)wmalloc((*textLen) + 4);
+ size_t slen;
+ int dLen;
+ char *textBuf;
+
+ dLen = WMWidthOfString(font, ".", 1);
+ slen = *textLen + 4;
+ textBuf = wmalloc(slen);
if (width >= 3 * dLen) {
- int dddLen = 3 * dLen;
int tmpTextLen = *textLen;
- strcpy(textBuf, text);
- while (tmpTextLen && (WMWidthOfString(font, textBuf,
tmpTextLen) + dddLen > width))
+ if (strlcpy(textBuf, text, slen) >= slen) {
+ wfree(textBuf);
+ return NULL;
+ }
+ while (tmpTextLen && (WMWidthOfString(font, textBuf,
tmpTextLen) + 3 * dLen > width))
tmpTextLen--;
- strcpy(textBuf + tmpTextLen, "...");
+ if (strlcpy(textBuf + tmpTextLen, "...", slen) >= slen) {
+ wfree(textBuf);
+ return NULL;
+ }
*textLen = tmpTextLen + 3;
} else if (width >= 2 * dLen) {
- strcpy(textBuf, "..");
+ if (strlcpy(textBuf, "..", slen) >= slen) {
+ wfree(textBuf);
+ return NULL;
+ }
*textLen = 2;
} else if (width >= dLen) {
- strcpy(textBuf, ".");
+ if (strlcpy(textBuf, ".", slen) >= slen) {
+ wfree(textBuf);
+ return NULL;
+ }
*textLen = 1;
} else {
*textBuf = '\0';
diff --git a/WINGs/wbutton.c b/WINGs/wbutton.c
index ae4ed4e..393707c 100644
--- a/WINGs/wbutton.c
+++ b/WINGs/wbutton.c
@@ -105,17 +105,13 @@ WMButton *WMCreateCustomButton(WMWidget * parent, int
behaviourMask)
Button *bPtr;
bPtr = wmalloc(sizeof(Button));
- memset(bPtr, 0, sizeof(Button));
-
bPtr->widgetClass = WC_Button;
-
bPtr->view = W_CreateView(W_VIEW(parent));
if (!bPtr->view) {
wfree(bPtr);
return NULL;
}
bPtr->view->self = bPtr;
-
bPtr->flags.type = 0;
bPtr->flags.springLoaded = (behaviourMask & WBBSpringLoadedMask) != 0;
diff --git a/WINGs/wcolor.c b/WINGs/wcolor.c
index 8c74f7c..bd0be1e 100644
--- a/WINGs/wcolor.c
+++ b/WINGs/wcolor.c
@@ -314,9 +314,13 @@ unsigned short WMGetColorAlpha(WMColor * color)
char *WMGetColorRGBDescription(WMColor * color)
{
- char *str = wmalloc(32);
+ char *str = wmalloc(8);
- sprintf(str, "#%02x%02x%02x", color->color.red >> 8, color->color.green
>> 8, color->color.blue >> 8);
+ if (snprintf(str, 8, "#%02x%02x%02x",
+ color->color.red >> 8, color->color.green >> 8,
color->color.blue >> 8) >= 8) {
+ wfree(str);
+ str = NULL;
+ }
return str;
}
diff --git a/WINGs/wcolorpanel.c b/WINGs/wcolorpanel.c
index 1aa5a57..b378ac7 100644
--- a/WINGs/wcolorpanel.c
+++ b/WINGs/wcolorpanel.c
@@ -374,7 +374,6 @@ static WMColorPanel *makeColorPanel(WMScreen * scrPtr, char
*name)
GC wgc = WMColorGC(scrPtr->white);
panel = wmalloc(sizeof(WMColorPanel));
- memset(panel, 0, sizeof(WMColorPanel));
panel->color.rgb.red = 0;
panel->color.rgb.green = 0;
@@ -1842,7 +1841,6 @@ static wheelMatrix *wheelCreateMatrix(unsigned int width,
unsigned int height)
assert((width > 0) && (height > 0));
matrix = wmalloc(sizeof(wheelMatrix));
- memset(matrix, 0, sizeof(wheelMatrix));
matrix->width = width;
matrix->height = height;
@@ -3446,14 +3444,7 @@ RColor ulongToRColor(WMScreen * scr, unsigned long value)
RColor color;
XColor *xcolor = NULL;
- if (!(xcolor = wmalloc(sizeof(XColor)))) {
- wwarning(_("Color Panel: Could not allocate memory"));
- color.red = 0;
- color.green = 0;
- color.blue = 0;
- color.alpha = 0;
- return color;
- }
+ xcolor = wmalloc(sizeof(XColor));
xcolor->pixel = value;
XQueryColor(scr->display, scr->rcontext->cmap, xcolor);
diff --git a/WINGs/wcolorwell.c b/WINGs/wcolorwell.c
index e35063d..19532d6 100644
--- a/WINGs/wcolorwell.c
+++ b/WINGs/wcolorwell.c
@@ -138,7 +138,6 @@ WMColorWell *WMCreateColorWell(WMWidget * parent)
ColorWell *cPtr;
cPtr = wmalloc(sizeof(ColorWell));
- memset(cPtr, 0, sizeof(ColorWell));
cPtr->widgetClass = WC_ColorWell;
diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c
index 29de7b5..85d9112 100644
--- a/WINGs/wfilepanel.c
+++ b/WINGs/wfilepanel.c
@@ -1,14 +1,16 @@
-#include "WINGsP.h"
-#include "wconfig.h"
-
#include <sys/types.h>
#include <sys/stat.h>
-#include <unistd.h>
+
#include <dirent.h>
-#include <limits.h>
#include <errno.h>
+#include <limits.h>
#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "WINGsP.h"
+#include "wconfig.h"
#ifndef PATH_MAX
#define PATH_MAX 1024
@@ -69,6 +71,7 @@ static void fillColumn(WMBrowserDelegate * self, WMBrowser *
bPtr, int column, W
static void deleteFile();
+static void normalizePath(char *s);
static void createDir();
static void goHome();
@@ -170,7 +173,6 @@ static WMFilePanel *makeFilePanel(WMScreen * scrPtr, char
*name, char *title)
WMPixmap *icon;
fPtr = wmalloc(sizeof(WMFilePanel));
- memset(fPtr, 0, sizeof(WMFilePanel));
fPtr->win = WMCreateWindowWithStyle(scrPtr, name, WMTitledWindowMask |
WMResizableWindowMask);
WMResizeWidget(fPtr->win, PWIDTH, PHEIGHT);
@@ -521,10 +523,15 @@ static void listDirectoryOnColumn(WMFilePanel * panel,
int column, char *path)
if (strcmp(dentry->d_name, ".") == 0 || strcmp(dentry->d_name,
"..") == 0)
continue;
- strcpy(pbuf, path);
+ if (strlcpy(pbuf, path, sizeof(pbuf)) >= sizeof(pbuf))
+ goto out;
+
if (strcmp(path, "/") != 0)
- strcat(pbuf, "/");
- strcat(pbuf, dentry->d_name);
+ if (strlcat(pbuf, "/", sizeof(pbuf)) >= sizeof(pbuf))
+ goto out;
+
+ if (strlcat(pbuf, dentry->d_name, sizeof(pbuf)) >= sizeof(pbuf))
+ goto out;
if (stat(pbuf, &stat_buf) != 0) {
#ifdef VERBOSE
@@ -542,6 +549,7 @@ static void listDirectoryOnColumn(WMFilePanel * panel, int
column, char *path)
}
WMSortBrowserColumnWithComparer(bPtr, column, comparer);
+out:
closedir(dir);
}
@@ -592,9 +600,39 @@ static void showError(WMScreen * scr, WMWindow * owner,
char *s, char *file)
wfree(errStr);
}
+/*
+ *----------------------------------------------------------------------
+ * normalizePath--
+ * Remove multiple consecutive and any trailing slashes from
+ * a path.
+ *----------------------------------------------------------------------
+ */
+static void normalizePath(char *s)
+{
+ int i, j, found;
+
+ found = 0;
+ for (i = 0; s[i]; !found && i++) {
+ found = 0;
+ if (s[i] == '/' && s[i+1] == '/') {
+ int nslash = 1;
+ found = 1;
+ i++;
+ while (s[i+nslash] == '/')
+ nslash++;
+ for (j = 0; s[i+j+nslash]; j++)
+ s[i+j] = s[i+j+nslash];
+ s[i+j] = '\0';
+ }
+ }
+ if (i > 1 && s[--i] == '/')
+ s[i] = '\0';
+}
+
static void createDir(WMButton * bPre, WMFilePanel * panel)
{
char *dirName, *directory, *file, *s;
+ size_t slen;
WMScreen *scr = WMWidgetScreen(panel->win);
dirName = WMRunInputPanel(scr, panel->win, _("Create Directory"),
@@ -602,39 +640,29 @@ static void createDir(WMButton * bPre, WMFilePanel *
panel)
if (!dirName)
return;
- directory = getCurrentFileName(panel);
- s = strrchr(directory, '/');
- if (s)
- s[1] = 0;
+ /* if `dirName' is an absolute path, don't mind `directory'.
+ * normalize as needed (possibly not needed at all?) */
- if (dirName[0] == '/') {
- directory[0] = 0;
+ normalizePath(dirName);
+ if (*dirName != '/') {
+ directory = getCurrentFileName(panel);
+ normalizePath(directory);
} else {
- while ((s = strstr(directory, "//"))) {
- int i;
- for (i = 2; s[i] == '/'; i++) ;
- strcpy(s, &s[i - 1]);
- }
- if ((s = strrchr(directory, '/')) && !s[1])
- s[0] = 0;
- }
- while ((s = strstr(dirName, "//"))) {
- int i;
- for (i = 2; s[i] == '/'; i++) ;
- strcpy(s, &s[i - 1]);
- }
- if ((s = strrchr(dirName, '/')) && !s[1])
- s[0] = 0;
-
- file = wmalloc(strlen(dirName) + strlen(directory) + 4);
- sprintf(file, "%s/%s", directory, dirName);
- while ((s = strstr(file, "//"))) {
- int i;
- for (i = 2; s[i] == '/'; i++) ;
- strcpy(s, &s[i - 1]);
+ directory = NULL;
}
- if (mkdir(file, 0xfff) != 0) {
+ slen = strlen(dirName) + (directory ? strlen(directory) + 1 /* "/" */
: 0) + 1 /* NULL */;
+ file = wmalloc(slen);
+
+ if (directory &&
+ (strlcat(file, directory, slen) >= slen ||
+ strlcat(file, "/", slen) >= slen))
+ goto out;
+
+ if (strlcat(file, dirName, slen) >= slen)
+ goto out;
+
+ if (mkdir(file, 00777) != 0) {
switch (errno) {
case EACCES:
showError(scr, panel->win, _("Permission denied."),
NULL);
@@ -648,8 +676,10 @@ static void createDir(WMButton * bPre, WMFilePanel * panel)
} else
WMSetFilePanelDirectory(panel, file);
+out:
wfree(dirName);
- wfree(directory);
+ if (directory)
+ wfree(directory);
wfree(file);
}
@@ -659,101 +689,40 @@ static void deleteFile(WMButton * bPre, WMFilePanel *
panel)
char *buffer, *s;
struct stat filestat;
WMScreen *scr = WMWidgetScreen(panel->win);
+#define __msgbufsize__ 512
+ buffer = wmalloc(__msgbufsize__);
file = getCurrentFileName(panel);
+ normalizePath(file);
- while ((s = strstr(file, "//"))) {
- int i;
- for (i = 2; s[i] == '/'; i++) ;
- strcpy(s, &s[i - 1]);
+ if (stat(file, &filestat) == -1) {
+ snprintf(buffer, __msgbufsize__, _("Can not find %s: %s"),
file, strerror(errno));
+ showError(scr, panel->win, buffer, NULL);
+ goto out;
}
- if (strlen(file) > 1 && (s = strrchr(file, '/')) && !s[1])
- s[0] = 0;
- if (stat(file, &filestat)) {
- switch (errno) {
- case ENOENT:
- showError(scr, panel->win, _("'%s' does not exist."),
file);
- break;
- case EACCES:
- showError(scr, panel->win, _("Permission denied."),
NULL);
- break;
- case ENOMEM:
- showError(scr, panel->win, _("Insufficient memory
available."), NULL);
- break;
- case EROFS:
- showError(scr, panel->win, _("'%s' is on a read-only
filesystem."), file);
- break;
- default:
- showError(scr, panel->win, _("Can not delete '%s'."),
file);
- }
- wfree(file);
- return;
- } else if (S_ISDIR(filestat.st_mode)) {
- int len = strlen(file) + 20;
- buffer = wmalloc(len);
- snprintf(buffer, len, _("Delete directory %s ?"), file);
- } else {
- int len = strlen(file) + 15;
- buffer = wmalloc(len);
- snprintf(buffer, len, _("Delete file %s ?"), file);
- }
+ snprintf(buffer, __msgbufsize__, _("Delete %s %s?"),
+ S_ISDIR(filestat.st_mode) ? _("directory") : _("file"), file);
if (!WMRunAlertPanel(WMWidgetScreen(panel->win), panel->win,
_("Warning"), buffer, _("OK"), _("Cancel"), NULL))
{
- if (S_ISDIR(filestat.st_mode)) {
- if (rmdir(file) != 0) {
- switch (errno) {
- case EACCES:
- showError(scr, panel->win,
_("Permission denied."), NULL);
- break;
- case ENOENT:
- showError(scr, panel->win, _("Directory
'%s' does not exist."), file);
- break;
- case ENOTEMPTY:
- showError(scr, panel->win, _("Directory
'%s' is not empty."), file);
- break;
- case EBUSY:
- showError(scr, panel->win, _("Directory
'%s' is busy."), file);
- break;
- default:
- showError(scr, panel->win, _("Can not
delete '%s'."), file);
- }
- } else {
- char *s = strrchr(file, '/');
- if (s)
- s[0] = 0;
- WMSetFilePanelDirectory(panel, file);
- }
- } else if (remove(file) != 0) {
- switch (errno) {
- case EISDIR:
- showError(scr, panel->win, _("'%s' is a
directory."), file);
- break;
- case ENOENT:
- showError(scr, panel->win, _("'%s' does not
exist."), file);
- break;
- case EACCES:
- showError(scr, panel->win, _("Permission
denied."), NULL);
- break;
- case ENOMEM:
- showError(scr, panel->win, _("Insufficient
memory available."), NULL);
- break;
- case EROFS:
- showError(scr, panel->win, _("'%s' is on a
read-only filesystem."), file);
- break;
- default:
- showError(scr, panel->win, _("Can not delete
'%s'."), file);
- }
+ if (remove(file) == -1) {
+ snprintf(buffer, __msgbufsize__, _("Removing %s failed:
%s"), file, strerror(errno));
+ showError(scr, panel->win, buffer, NULL);
+
} else {
char *s = strrchr(file, '/');
if (s)
- s[1] = 0;
+ *s = 0;
WMSetFilePanelDirectory(panel, file);
}
}
- wfree(buffer);
- wfree(file);
+out:
+ if (buffer)
+ wfree(buffer);
+ if (file)
+ wfree(file);
+#undef __msgbufsize__
}
static void goUnmount(WMButton * bPtr, WMFilePanel * panel)
diff --git a/WINGs/wfont.c b/WINGs/wfont.c
index 6cbdea2..245cdcc 100644
--- a/WINGs/wfont.c
+++ b/WINGs/wfont.c
@@ -139,7 +139,6 @@ WMFont *WMCreateFont(WMScreen * scrPtr, char *fontName)
}
font = wmalloc(sizeof(WMFont));
- memset(font, 0, sizeof(WMFont));
font->screen = scrPtr;
diff --git a/WINGs/wfontpanel.c b/WINGs/wfontpanel.c
index 0cca5d6..806cc2c 100644
--- a/WINGs/wfontpanel.c
+++ b/WINGs/wfontpanel.c
@@ -165,7 +165,6 @@ WMFontPanel *WMGetFontPanel(WMScreen * scr)
return scr->sharedFontPanel;
panel = wmalloc(sizeof(FontPanel));
- memset(panel, 0, sizeof(FontPanel));
panel->win = WMCreateWindow(scr, "fontPanel");
/* WMSetWidgetBackgroundColor(panel->win, WMWhiteColor(scr)); */
@@ -461,7 +460,6 @@ static void addTypefaceToXftFamily(Family * fam, char
*style)
}
face = wmalloc(sizeof(Typeface));
- memset(face, 0, sizeof(Typeface));
face->typeface = wstrdup(style);
face->sizes = WMCreateArray(4);
@@ -493,7 +491,6 @@ static void addFontToXftFamily(WMHashTable * families, char
*name, char *style)
array = WMCreateArray(8);
fam = wmalloc(sizeof(Family));
- memset(fam, 0, sizeof(Family));
fam->name = wstrdup(name);
@@ -548,7 +545,7 @@ static void listFamilies(WMScreen * scr, WMFontPanel *
panel)
WMListItem *item;
WM_ITERATE_ARRAY(array, fam, i) {
- strcpy(buffer, fam->name);
+ strlcpy(buffer, fam->name, sizeof(buffer)); /* if it
gets truncated, so be it */
item = WMAddListItem(panel->famLs, buffer);
item->clientData = fam;
@@ -630,7 +627,7 @@ static void familyClick(WMWidget * w, void *data)
int top = 0;
WMListItem *fitem;
- strcpy(buffer, face->typeface);
+ strlcpy(buffer, face->typeface, sizeof(buffer)); /* if it gets
truncated, so be it */
if (strcasecmp(face->typeface, "Roman") == 0)
top = 1;
if (strcasecmp(face->typeface, "Regular") == 0)
@@ -755,7 +752,7 @@ static void setFontPanelFontName(FontPanel * panel, char
*family, char *style, d
int top = 0;
WMListItem *fitem;
- strcpy(buffer, face->typeface);
+ strlcpy(buffer, face->typeface, sizeof(buffer));
if (strcasecmp(face->typeface, "Roman") == 0)
top = 1;
if (top)
diff --git a/WINGs/wframe.c b/WINGs/wframe.c
index 27f2b57..b7b30b5 100644
--- a/WINGs/wframe.c
+++ b/WINGs/wframe.c
@@ -221,7 +221,6 @@ WMFrame *WMCreateFrame(WMWidget * parent)
Frame *fPtr;
fPtr = wmalloc(sizeof(Frame));
- memset(fPtr, 0, sizeof(Frame));
fPtr->widgetClass = WC_Frame;
diff --git a/WINGs/wlabel.c b/WINGs/wlabel.c
index 8b67d93..589f4b3 100644
--- a/WINGs/wlabel.c
+++ b/WINGs/wlabel.c
@@ -39,7 +39,6 @@ WMLabel *WMCreateLabel(WMWidget * parent)
Label *lPtr;
lPtr = wmalloc(sizeof(Label));
- memset(lPtr, 0, sizeof(Label));
lPtr->widgetClass = WC_Label;
diff --git a/WINGs/wlist.c b/WINGs/wlist.c
index f8fbde8..b58d68d 100644
--- a/WINGs/wlist.c
+++ b/WINGs/wlist.c
@@ -110,7 +110,6 @@ WMList *WMCreateList(WMWidget * parent)
W_Screen *scrPtr = W_VIEW(parent)->screen;
lPtr = wmalloc(sizeof(List));
- memset(lPtr, 0, sizeof(List));
lPtr->widgetClass = WC_List;
@@ -187,7 +186,6 @@ WMListItem *WMInsertListItem(WMList * lPtr, int row, char
*text)
CHECK_CLASS(lPtr, WC_List);
item = wmalloc(sizeof(WMListItem));
- memset(item, 0, sizeof(WMListItem));
item->text = wstrdup(text);
row = WMIN(row, WMGetArrayItemCount(lPtr->items));
diff --git a/WINGs/wmenuitem.c b/WINGs/wmenuitem.c
index a956861..09571d4 100644
--- a/WINGs/wmenuitem.c
+++ b/WINGs/wmenuitem.c
@@ -41,7 +41,6 @@ WMMenuItem *WMCreateMenuItem(void)
WMMenuItem *item;
item = wmalloc(sizeof(MenuItem));
- memset(item, 0, sizeof(MenuItem));
item->flags.enabled = 1;
diff --git a/WINGs/wpanel.c b/WINGs/wpanel.c
index f85804f..7e3f9f5 100644
--- a/WINGs/wpanel.c
+++ b/WINGs/wpanel.c
@@ -94,7 +94,6 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow
* owner,
WMPixmap *icon;
panel = wmalloc(sizeof(WMAlertPanel));
- memset(panel, 0, sizeof(WMAlertPanel));
if (owner) {
panel->win = WMCreatePanelWithStyleForWindow(owner,
"alertPanel", WMTitledWindowMask);
@@ -342,7 +341,6 @@ WMInputPanel *WMCreateInputPanel(WMScreen * scrPtr,
WMWindow * owner, char *titl
int x, dw = 0, aw = 0, w;
panel = wmalloc(sizeof(WMInputPanel));
- memset(panel, 0, sizeof(WMInputPanel));
if (owner)
panel->win = WMCreatePanelWithStyleForWindow(owner,
"inputPanel", WMTitledWindowMask);
@@ -464,7 +462,6 @@ WMGenericPanel *WMCreateGenericPanel(WMScreen * scrPtr,
WMWindow * owner,
WMPixmap *icon;
panel = wmalloc(sizeof(WMGenericPanel));
- memset(panel, 0, sizeof(WMGenericPanel));
if (owner) {
panel->win = WMCreatePanelWithStyleForWindow(owner,
"genericPanel", WMTitledWindowMask);
diff --git a/WINGs/wpopupbutton.c b/WINGs/wpopupbutton.c
index ba43ce7..648039a 100644
--- a/WINGs/wpopupbutton.c
+++ b/WINGs/wpopupbutton.c
@@ -57,7 +57,6 @@ WMPopUpButton *WMCreatePopUpButton(WMWidget * parent)
W_Screen *scr = W_VIEW(parent)->screen;
bPtr = wmalloc(sizeof(PopUpButton));
- memset(bPtr, 0, sizeof(PopUpButton));
bPtr->widgetClass = WC_PopUpButton;
diff --git a/WINGs/wprogressindicator.c b/WINGs/wprogressindicator.c
index 5e83e23..a897a9e 100644
--- a/WINGs/wprogressindicator.c
+++ b/WINGs/wprogressindicator.c
@@ -43,7 +43,6 @@ WMProgressIndicator *WMCreateProgressIndicator(WMWidget *
parent)
ProgressIndicator *pPtr;
pPtr = wmalloc(sizeof(ProgressIndicator));
- memset(pPtr, 0, sizeof(ProgressIndicator));
pPtr->widgetClass = WC_ProgressIndicator;
diff --git a/WINGs/wruler.c b/WINGs/wruler.c
index 2b9b119..f8d4af0 100644
--- a/WINGs/wruler.c
+++ b/WINGs/wruler.c
@@ -384,8 +384,6 @@ WMRuler *WMCreateRuler(WMWidget * parent)
Ruler *rPtr = wmalloc(sizeof(Ruler));
unsigned int w = WMWidgetWidth(parent);
- memset(rPtr, 0, sizeof(Ruler));
-
rPtr->widgetClass = WC_Ruler;
rPtr->view = W_CreateView(W_VIEW(parent));
diff --git a/WINGs/wscroller.c b/WINGs/wscroller.c
index 33afa4e..b28825e 100644
--- a/WINGs/wscroller.c
+++ b/WINGs/wscroller.c
@@ -84,7 +84,6 @@ WMScroller *WMCreateScroller(WMWidget * parent)
Scroller *sPtr;
sPtr = wmalloc(sizeof(Scroller));
- memset(sPtr, 0, sizeof(Scroller));
sPtr->widgetClass = WC_Scroller;
diff --git a/WINGs/wscrollview.c b/WINGs/wscrollview.c
index 7733e27..692da6a 100644
--- a/WINGs/wscrollview.c
+++ b/WINGs/wscrollview.c
@@ -44,7 +44,6 @@ WMScrollView *WMCreateScrollView(WMWidget * parent)
ScrollView *sPtr;
sPtr = wmalloc(sizeof(ScrollView));
- memset(sPtr, 0, sizeof(ScrollView));
sPtr->widgetClass = WC_ScrollView;
diff --git a/WINGs/wslider.c b/WINGs/wslider.c
index 110c858..e54efda 100644
--- a/WINGs/wslider.c
+++ b/WINGs/wslider.c
@@ -57,7 +57,6 @@ WMSlider *WMCreateSlider(WMWidget * parent)
Slider *sPtr;
sPtr = wmalloc(sizeof(Slider));
- memset(sPtr, 0, sizeof(Slider));
sPtr->widgetClass = WC_Slider;
diff --git a/WINGs/wsplitview.c b/WINGs/wsplitview.c
index e8cb383..17ec023 100644
--- a/WINGs/wsplitview.c
+++ b/WINGs/wsplitview.c
@@ -607,7 +607,6 @@ WMSplitView *WMCreateSplitView(WMWidget * parent)
WMSplitView *sPtr;
sPtr = wmalloc(sizeof(WMSplitView));
- memset(sPtr, 0, sizeof(WMSplitView));
sPtr->widgetClass = WC_SplitView;
@@ -651,7 +650,8 @@ void WMAddSplitViewSubview(WMSplitView * sPtr, WMView *
subview)
CHECK_CLASS(sPtr, WC_SplitView);
- if (!(p = (W_SplitViewSubview *) wmalloc(sizeof(W_SplitViewSubview))))
+ p = (W_SplitViewSubview *) wmalloc(sizeof(W_SplitViewSubview));
+ if (!p)
return;
wasMapped = subview->flags.mapped;
diff --git a/WINGs/wtabview.c b/WINGs/wtabview.c
index 3ae4728..663f4b9 100644
--- a/WINGs/wtabview.c
+++ b/WINGs/wtabview.c
@@ -190,7 +190,6 @@ WMTabView *WMCreateTabView(WMWidget * parent)
WMScreen *scr = WMWidgetScreen(parent);
tPtr = wmalloc(sizeof(TabView));
- memset(tPtr, 0, sizeof(TabView));
tPtr->widgetClass = WC_TabView;
@@ -819,7 +818,6 @@ WMTabViewItem *WMCreateTabViewItemWithIdentifier(int
identifier)
WMTabViewItem *item;
item = wmalloc(sizeof(WMTabViewItem));
- memset(item, 0, sizeof(WMTabViewItem));
item->identifier = identifier;
@@ -833,7 +831,6 @@ WMTabViewItem *WMCreateTabViewItem(int identifier, char
*label)
WMTabViewItem *item;
item = wmalloc(sizeof(WMTabViewItem));
- memset(item, 0, sizeof(WMTabViewItem));
item->identifier = identifier;
diff --git a/WINGs/wtext.c b/WINGs/wtext.c
index 01772c4..ece4b39 100644
--- a/WINGs/wtext.c
+++ b/WINGs/wtext.c
@@ -2935,7 +2935,6 @@ WMText *WMCreateTextForDocumentType(WMWidget * parent,
WMAction * parser, WMActi
XGCValues gcv;
tPtr = wmalloc(sizeof(Text));
- memset(tPtr, 0, sizeof(Text));
tPtr->widgetClass = WC_Text;
tPtr->view = W_CreateView(W_VIEW(parent));
if (!tPtr->view) {
@@ -3232,7 +3231,6 @@ void *WMCreateTextBlockWithText(WMText * tPtr, char
*text, WMFont * font, WMColo
tb->allocated = reqBlockSize(len);
tb->text = (char *)wmalloc(tb->allocated);
- memset(tb->text, 0, tb->allocated);
if (len < 1 || !text || (*text == '\n' && len == 1)) {
*tb->text = ' ';
diff --git a/WINGs/wtextfield.c b/WINGs/wtextfield.c
index e353ee6..c8e0414 100644
--- a/WINGs/wtextfield.c
+++ b/WINGs/wtextfield.c
@@ -316,7 +316,6 @@ WMTextField *WMCreateTextField(WMWidget * parent)
TextField *tPtr;
tPtr = wmalloc(sizeof(TextField));
- memset(tPtr, 0, sizeof(TextField));
tPtr->widgetClass = WC_TextField;
@@ -399,7 +398,7 @@ void WMInsertTextFieldText(WMTextField * tPtr, char *text,
int position)
if (position < 0 || position >= tPtr->textLen) {
/* append the text at the end */
- strcat(tPtr->text, text);
+ strlcat(tPtr->text, text, tPtr->bufferSize);
tPtr->textLen += len;
tPtr->cursorPosition += len;
incrToFit(tPtr);
@@ -468,7 +467,7 @@ void WMSetTextFieldText(WMTextField * tPtr, char *text)
tPtr->bufferSize = tPtr->textLen + TEXT_BUFFER_INCR;
tPtr->text = wrealloc(tPtr->text, tPtr->bufferSize);
}
- strcpy(tPtr->text, text);
+ strlcpy(tPtr->text, text, tPtr->bufferSize);
}
tPtr->cursorPosition = tPtr->selection.position = tPtr->textLen;
diff --git a/WINGs/wview.c b/WINGs/wview.c
index da7329e..982a9e7 100644
--- a/WINGs/wview.c
+++ b/WINGs/wview.c
@@ -93,7 +93,6 @@ static W_View *createView(W_Screen * screen, W_View * parent)
ViewContext = XUniqueContext();
view = wmalloc(sizeof(W_View));
- memset(view, 0, sizeof(W_View));
view->screen = screen;
diff --git a/WINGs/wwindow.c b/WINGs/wwindow.c
index 565b392..16db234 100644
--- a/WINGs/wwindow.c
+++ b/WINGs/wwindow.c
@@ -135,7 +135,6 @@ WMWindow *WMCreateWindowWithStyle(WMScreen * screen, char
*name, int style)
_Window *win;
win = wmalloc(sizeof(_Window));
- memset(win, 0, sizeof(_Window));
win->widgetClass = WC_Window;
diff --git a/configure.ac b/configure.ac
index 516154c..05525be 100644
--- a/configure.ac
+++ b/configure.ac
@@ -150,6 +150,9 @@ AC_FUNC_VPRINTF
AC_CHECK_FUNCS(gethostname select poll strerror strcasecmp strncasecmp \
setsid atexit mallinfo mkstemp)
+AC_CHECK_FUNC(strlcat, AC_DEFINE(HAVE_STRLCAT, 1, Check for strlcat))
+AC_CHECK_FUNC(strlcpy, AC_DEFINE(HAVE_STRLCPY, 1, Check for strlcpy))
+
dnl Check for inotify
dnl =================
AC_CHECK_HEADERS(sys/inotify.h, AC_DEFINE(HAVE_INOTIFY, 1, Check for inotify))
@@ -197,8 +200,8 @@ dnl Checks for typedefs, structures, and compiler
characteristics.
dnl ==============================================================
AC_DECL_SYS_SIGLIST
AC_C_CONST
-#AC_TYPE_SIZE_T
-#AC_TYPE_PID_T
+AC_TYPE_SIZE_T
+AC_TYPE_PID_T
AC_TYPE_SIGNAL
@@ -448,7 +451,7 @@ if test "$shape" = yes; then
fi
dnl XRandR support
-dnl =============
+dnl ==============
xrandr=yes
AC_ARG_ENABLE(XRandR, AS_HELP_STRING([--disable-xrandr], [disable XRandR
window extension support]),
xrandr=$enableval, xrandr=yes)
@@ -835,7 +838,7 @@ AC_SUBST(wprefs_bindir)
dnl Enable User Defined Menu thing
-dnl ==================================
+dnl ==============================
AC_ARG_ENABLE(usermenu, AS_HELP_STRING([--enable-usermenu], [user defined
menus for applications]),
if test "$enableval" = yes; then
AC_DEFINE(USER_MENU, 1, [define if you want user defined menus for
applications])
--
[-]
mkdir /nonexistent
--
To unsubscribe, send mail to [email protected].