On Thu, 23 Sep 2010, Carlos R. Mafra wrote:
> > please eye this (will turn it into a proper git patch once it's deemed
> > committable)
>
> First, thanks a lot for doing these non-trivial changes.
but no, thanks to you for watching over them.
> But it's a big patch with several (unrelated) changes, making it somehow
> difficult to read through. The overall result seems to be quite nice, AFAICT.
> Nothing will beat the test of time, though :-)
>
> But for bisectability and review purposes, it should be splitted a bit.
> I realize it may be a pain to separate it now, but it's worth it.
indeed. i've known that from the beginning, but... :)
i've attached a number of patches, which should be applied in the
following order (please let's not open discussion about my git-fu,
i'll eventually get to that...):
1 0001-Make-wmalloc-intialize-allocated-memory-to-0.patch
2 0001-Return-NULL-on-NULL-input-in-wapplication.c-checkFil.patch
3 0001-Simplify-WINGs-wapplicationc-WMPathForResourceOfType.patch
4 0001-Add-WINGs-wfilepanel.c-normalizePath.patch
5 0001-Simplify-and-rationalize-WINGs-wfilepanel.c-createDi.patch
these cover everything in the big patch, save for strl* (and a couple
of small items i'll have to review closely).
these are all supposed to be fairly straightforward and low-impact (or
at least errors in them will manifest themself fast and hard).
the lot has been tested a bit, no ill effects here.
i will re-do the strl* bits a bit later.
--
[-]
mkdir /nonexistent
From eb03cb25eddcdcf4ffc4b634977d27343931ba11 Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Thu, 23 Sep 2010 14:27:48 +0200
Subject: [PATCH] Make wmalloc() intialize allocated memory to 0
- Accordingly remove individual memsets, for now from WINGs only.
Signed-off-by: Tamas TEVESZ <[email protected]>
---
WINGs/bagtree.c | 6 ------
WINGs/hashtable.c | 1 -
WINGs/memory.c | 1 +
WINGs/notification.c | 5 -----
WINGs/proplist.c | 4 ----
WINGs/selection.c | 3 ---
WINGs/string.c | 2 --
WINGs/tree.c | 3 ---
WINGs/userdefaults.c | 8 +-------
WINGs/wballoon.c | 1 -
WINGs/wbox.c | 1 -
WINGs/wbrowser.c | 1 -
WINGs/wcolorpanel.c | 13 +------------
WINGs/wcolorwell.c | 1 -
WINGs/wfilepanel.c | 1 -
WINGs/wfont.c | 1 -
WINGs/wfontpanel.c | 2 --
WINGs/wframe.c | 1 -
WINGs/wlabel.c | 1 -
WINGs/wlist.c | 2 --
WINGs/wmenuitem.c | 1 -
WINGs/wpanel.c | 3 ---
WINGs/wpopupbutton.c | 1 -
WINGs/wprogressindicator.c | 1 -
WINGs/wruler.c | 2 --
WINGs/wscroller.c | 2 --
WINGs/wscrollview.c | 2 --
WINGs/wslider.c | 2 --
WINGs/wsplitview.c | 2 --
WINGs/wtabview.c | 10 +---------
WINGs/wtext.c | 2 --
WINGs/wtextfield.c | 3 ---
WINGs/wview.c | 2 --
WINGs/wwindow.c | 2 --
34 files changed, 4 insertions(+), 89 deletions(-)
diff --git a/WINGs/bagtree.c b/WINGs/bagtree.c
index a37c2d4..bf1ac48 100644
--- a/WINGs/bagtree.c
+++ b/WINGs/bagtree.c
@@ -358,16 +358,10 @@ WMBag *WMCreateTreeBagWithDestructor(WMFreeDataProc * destructor)
WMBag *bag;
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;
-
bag->root = bag->nil;
-
bag->destructor = destructor;
return bag;
diff --git a/WINGs/hashtable.c b/WINGs/hashtable.c
index a85f0ee..9822c4e 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++) {
diff --git a/WINGs/memory.c b/WINGs/memory.c
index 0e350bf..39c7fc9 100644
--- a/WINGs/memory.c
+++ b/WINGs/memory.c
@@ -98,6 +98,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..b07739d 100644
--- a/WINGs/selection.c
+++ b/WINGs/selection.c
@@ -341,7 +341,6 @@ 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;
@@ -373,14 +372,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..5dbba85 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)
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..ea5cceb 100644
--- a/WINGs/userdefaults.c
+++ b/WINGs/userdefaults.c
@@ -263,10 +263,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 +352,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/wballoon.c b/WINGs/wballoon.c
index 1b33a89..de8c502 100644
--- a/WINGs/wballoon.c
+++ b/WINGs/wballoon.c
@@ -50,7 +50,6 @@ 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) {
diff --git a/WINGs/wbox.c b/WINGs/wbox.c
index 2c7d949..494f590 100644
--- a/WINGs/wbox.c
+++ b/WINGs/wbox.c
@@ -44,7 +44,6 @@ WMBox *WMCreateBox(WMWidget * parent)
Box *bPtr;
bPtr = wmalloc(sizeof(Box));
- memset(bPtr, 0, sizeof(Box));
bPtr->widgetClass = WC_Box;
diff --git a/WINGs/wbrowser.c b/WINGs/wbrowser.c
index b539543..440acb9 100644
--- a/WINGs/wbrowser.c
+++ b/WINGs/wbrowser.c
@@ -95,7 +95,6 @@ WMBrowser *WMCreateBrowser(WMWidget * parent)
wassertrv(parent, NULL);
bPtr = wmalloc(sizeof(WMBrowser));
- memset(bPtr, 0, sizeof(WMBrowser));
bPtr->widgetClass = WC_Browser;
diff --git a/WINGs/wcolorpanel.c b/WINGs/wcolorpanel.c
index 1aa5a57..e18278e 100644
--- a/WINGs/wcolorpanel.c
+++ b/WINGs/wcolorpanel.c
@@ -374,8 +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;
panel->color.rgb.blue = 0;
@@ -1842,7 +1840,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,15 +3443,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..ef13312 100644
--- a/WINGs/wfilepanel.c
+++ b/WINGs/wfilepanel.c
@@ -170,7 +170,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);
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..91954b6 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);
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..6afca48 100644
--- a/WINGs/wscroller.c
+++ b/WINGs/wscroller.c
@@ -84,8 +84,6 @@ WMScroller *WMCreateScroller(WMWidget * parent)
Scroller *sPtr;
sPtr = wmalloc(sizeof(Scroller));
- memset(sPtr, 0, sizeof(Scroller));
-
sPtr->widgetClass = WC_Scroller;
sPtr->view = W_CreateView(W_VIEW(parent));
diff --git a/WINGs/wscrollview.c b/WINGs/wscrollview.c
index 7733e27..8b33812 100644
--- a/WINGs/wscrollview.c
+++ b/WINGs/wscrollview.c
@@ -44,8 +44,6 @@ WMScrollView *WMCreateScrollView(WMWidget * parent)
ScrollView *sPtr;
sPtr = wmalloc(sizeof(ScrollView));
- memset(sPtr, 0, sizeof(ScrollView));
-
sPtr->widgetClass = WC_ScrollView;
sPtr->view = W_CreateView(W_VIEW(parent));
diff --git a/WINGs/wslider.c b/WINGs/wslider.c
index 110c858..1ee7dae 100644
--- a/WINGs/wslider.c
+++ b/WINGs/wslider.c
@@ -57,8 +57,6 @@ WMSlider *WMCreateSlider(WMWidget * parent)
Slider *sPtr;
sPtr = wmalloc(sizeof(Slider));
- memset(sPtr, 0, sizeof(Slider));
-
sPtr->widgetClass = WC_Slider;
sPtr->view = W_CreateView(W_VIEW(parent));
diff --git a/WINGs/wsplitview.c b/WINGs/wsplitview.c
index e8cb383..a26ba12 100644
--- a/WINGs/wsplitview.c
+++ b/WINGs/wsplitview.c
@@ -607,8 +607,6 @@ WMSplitView *WMCreateSplitView(WMWidget * parent)
WMSplitView *sPtr;
sPtr = wmalloc(sizeof(WMSplitView));
- memset(sPtr, 0, sizeof(WMSplitView));
-
sPtr->widgetClass = WC_SplitView;
sPtr->view = W_CreateView(W_VIEW(parent));
diff --git a/WINGs/wtabview.c b/WINGs/wtabview.c
index 3ae4728..df72d48 100644
--- a/WINGs/wtabview.c
+++ b/WINGs/wtabview.c
@@ -190,8 +190,6 @@ WMTabView *WMCreateTabView(WMWidget * parent)
WMScreen *scr = WMWidgetScreen(parent);
tPtr = wmalloc(sizeof(TabView));
- memset(tPtr, 0, sizeof(TabView));
-
tPtr->widgetClass = WC_TabView;
tPtr->view = W_CreateView(W_VIEW(parent));
@@ -258,7 +256,7 @@ void WMInsertItemInTabView(WMTabView * tPtr, int index, WMTabViewItem * item)
WMTabViewItem **items;
items = wrealloc(tPtr->items, sizeof(WMTabViewItem *) * (tPtr->maxItems + 10));
- memset(&items[tPtr->maxItems], 0, sizeof(WMTabViewItem *) * 10);
+ memset(&items[tPtr->maxItems], 0, sizeof(WMTabViewItem *) * 10); /* XXX */
tPtr->items = items;
tPtr->maxItems += 10;
}
@@ -819,10 +817,7 @@ WMTabViewItem *WMCreateTabViewItemWithIdentifier(int identifier)
WMTabViewItem *item;
item = wmalloc(sizeof(WMTabViewItem));
- memset(item, 0, sizeof(WMTabViewItem));
-
item->identifier = identifier;
-
item->flags.enabled = 1;
return item;
@@ -833,10 +828,7 @@ WMTabViewItem *WMCreateTabViewItem(int identifier, char *label)
WMTabViewItem *item;
item = wmalloc(sizeof(WMTabViewItem));
- memset(item, 0, sizeof(WMTabViewItem));
-
item->identifier = identifier;
-
item->flags.enabled = 1;
WMSetTabViewItemLabel(item, label);
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..a2af3a1 100644
--- a/WINGs/wtextfield.c
+++ b/WINGs/wtextfield.c
@@ -316,8 +316,6 @@ WMTextField *WMCreateTextField(WMWidget * parent)
TextField *tPtr;
tPtr = wmalloc(sizeof(TextField));
- memset(tPtr, 0, sizeof(TextField));
-
tPtr->widgetClass = WC_TextField;
tPtr->view = W_CreateView(W_VIEW(parent));
@@ -335,7 +333,6 @@ WMTextField *WMCreateTextField(WMWidget * parent)
W_SetViewBackgroundColor(tPtr->view, tPtr->view->screen->white);
tPtr->text = wmalloc(MIN_TEXT_BUFFER);
- tPtr->text[0] = 0;
tPtr->textLen = 0;
tPtr->bufferSize = MIN_TEXT_BUFFER;
diff --git a/WINGs/wview.c b/WINGs/wview.c
index da7329e..5c6ecb3 100644
--- a/WINGs/wview.c
+++ b/WINGs/wview.c
@@ -93,8 +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;
if (parent != NULL) {
diff --git a/WINGs/wwindow.c b/WINGs/wwindow.c
index 565b392..53b98e8 100644
--- a/WINGs/wwindow.c
+++ b/WINGs/wwindow.c
@@ -135,8 +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;
win->view = W_CreateTopView(screen);
--
1.7.0.4
From 13b43e2961341f9a3f006cdd21292d4a61e3a306 Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Thu, 23 Sep 2010 14:30:19 +0200
Subject: [PATCH] Return NULL on NULL input in wapplication.c:checkFile()
Signed-off-by: Tamas TEVESZ <[email protected]>
---
WINGs/wapplication.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/WINGs/wapplication.c b/WINGs/wapplication.c
index 620e378..df1a52f 100644
--- a/WINGs/wapplication.c
+++ b/WINGs/wapplication.c
@@ -66,6 +66,9 @@ static char *checkFile(char *path, char *folder, char *ext, char *resource)
char *ret;
int extralen;
+ if (!path || !resource)
+ return NULL;
+
extralen = (ext ? strlen(ext) : 0) + (folder ? strlen(folder) : 0) + 4;
ret = wmalloc(strlen(path) + strlen(resource) + extralen + 8);
strcpy(ret, path);
--
1.7.0.4
From 6c8937f89c7b0f98f50d85a38d076c0c6b4c0dbc Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Thu, 23 Sep 2010 14:46:09 +0200
Subject: [PATCH] Simplify WINGs/wapplicationc:WMPathForResourceOfType()
Signed-off-by: Tamas TEVESZ <[email protected]>
---
WINGs/wapplication.c | 80 ++++++++++++++++++++-----------------------------
1 files changed, 33 insertions(+), 47 deletions(-)
diff --git a/WINGs/wapplication.c b/WINGs/wapplication.c
index df1a52f..570dc01 100644
--- a/WINGs/wapplication.c
+++ b/WINGs/wapplication.c
@@ -93,14 +93,16 @@ static char *checkFile(char *path, char *folder, char *ext, char *resource)
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
@@ -112,7 +114,7 @@ char *WMPathForResourceOfType(char *resource, char *ext)
if (WMApplication.resourcePath) {
path = checkFile(WMApplication.resourcePath, NULL, ext, resource);
if (path)
- return path;
+ goto out;
}
if (WMApplication.argv[0]) {
@@ -126,58 +128,42 @@ char *WMPathForResourceOfType(char *resource, char *ext)
} else {
path = NULL;
}
- wfree(tmp);
- if (path)
- return path;
+ goto out;
}
- 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;
+
}
--
1.7.0.4
From 16f0fbf08291a6a1ca69dc13093d3d085bee45e3 Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Thu, 23 Sep 2010 15:34:05 +0200
Subject: [PATCH] Add WINGs/wfilepanel.c:normalizePath()
Removes multiple consecutive and any trailing slashes from
a path-looking string
Signed-off-by: Tamas TEVESZ <[email protected]>
---
WINGs/wfilepanel.c | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c
index ef13312..058de9c 100644
--- a/WINGs/wfilepanel.c
+++ b/WINGs/wfilepanel.c
@@ -69,6 +69,8 @@ static void fillColumn(WMBrowserDelegate * self, WMBrowser * bPtr, int column, W
static void deleteFile();
+static void normalizePath(char *s);
+
static void createDir();
static void goHome();
@@ -652,6 +654,36 @@ static void createDir(WMButton * bPre, WMFilePanel * panel)
wfree(file);
}
+/*
+ *----------------------------------------------------------------------
+ * 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 deleteFile(WMButton * bPre, WMFilePanel * panel)
{
char *file;
--
1.7.0.4
From 69a68386486553c0ee27c4419d9304aa50bc78a9 Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Thu, 23 Sep 2010 16:34:56 +0200
Subject: [PATCH] Simplify and rationalize WINGs/wfilepanel.c:createDir() and deleteFile()
Signed-off-by: Tamas TEVESZ <[email protected]>
---
WINGs/wfilepanel.c | 186 ++++++++++++++++------------------------------------
1 files changed, 57 insertions(+), 129 deletions(-)
diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c
index 058de9c..5427879 100644
--- a/WINGs/wfilepanel.c
+++ b/WINGs/wfilepanel.c
@@ -67,10 +67,10 @@ static void browserDClick();
static void fillColumn(WMBrowserDelegate * self, WMBrowser * bPtr, int column, WMList * list);
-static void deleteFile();
-
static void normalizePath(char *s);
+static void deleteFile();
+
static void createDir();
static void goHome();
@@ -596,6 +596,7 @@ static void showError(WMScreen * scr, WMWindow * owner, char *s, char *file)
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"),
@@ -603,55 +604,43 @@ static void createDir(WMButton * bPre, WMFilePanel * panel)
if (!dirName)
return;
- directory = getCurrentFileName(panel);
- s = strrchr(directory, '/');
- if (s)
- s[1] = 0;
-
- if (dirName[0] == '/') {
- directory[0] = 0;
+ /* if `dirName' is an absolute path, don't mind `directory'.
+ * normalize as needed (possibly not needed at all?) */
+ 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;
+ directory = NULL;
}
- 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]);
+
+ slen = strlen(dirName) + (directory ? strlen(directory) + 1 /* "/" */ : 0) + 1 /* NULL */;
+ file = wmalloc(slen);
+
+ if (directory) {
+ strncpy(file, directory, slen - 1);
+ strncat(file, "/", slen - strlen(file));
}
- if (mkdir(file, 0xfff) != 0) {
- switch (errno) {
- case EACCES:
- showError(scr, panel->win, _("Permission denied."), NULL);
- break;
- case EEXIST:
- showError(scr, panel->win, _("'%s' already exists."), file);
- break;
- case ENOENT:
- showError(scr, panel->win, _("Path does not exist."), NULL);
- }
- } else
+ strncat(file, dirName, slen - strlen(file));
+
+ if (mkdir(file, 00777) != 0) {
+#define __msgbufsize__ 512
+ char *buffer = wmalloc(__msgbufsize__);
+ snprintf(buffer, __msgbufsize__, _("Can not create %d: %d"), file, strerror(errno));
+ showError(scr, panel->win, buffer, NULL);
+ wfree(buffer);
+#undef __msgbufsize__
+ } else {
WMSetFilePanelDirectory(panel, file);
+ }
- wfree(dirName);
- wfree(directory);
- wfree(file);
+ if (dirName)
+ wfree(dirName);
+ if (directory)
+ wfree(directory);
+ if (file)
+ wfree(file);
}
/*
@@ -686,105 +675,44 @@ static void normalizePath(char *s)
static void deleteFile(WMButton * bPre, WMFilePanel * panel)
{
- char *file;
- char *buffer, *s;
+ char *file, *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 (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);
+ if (stat(file, &filestat) == -1) {
+ snprintf(buffer, __msgbufsize__, _("Can not find %s: %s"), file, strerror(errno));
+ showError(scr, panel->win, buffer, NULL);
+ goto out;
}
+ 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] = 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)
--
1.7.0.4