It is safer if the functions are declared with proper
prototype specifications.
This patch addresses some of the warnings with -Wstrict-prototype,
like this:
event.c:105: warning: function declaration isn't a prototype
After the fix to avoid a memory leak in wtokenfree(), WPrefs crashes
when opening the 'Applications Menu Definition' dialogue.
The problem is that WPrefs code relied on the fact that the first token
in the array would not be free'd by wtokenfree(), a misbehaviour which
is correctly addressed with this patch.
Retrieved-from: http://www.mail-archive.com/ports@openbsd.org/msg12731.html
[crmafra: small changes in the commit log from the webpage]
wtokenfree() does not free the first entry of an array.
If count is 1 then
while (--count)
will be
while (0)
and the inner body of that while-loop will not be entered.
Therefore a memory leak happens every time wtokenfree() is called.
Retrieved-from: http://paldium.homeunix.org/tobias/wmaker/patches/
[crmafra: This patch, altough correct, breaks WPrefs.app, which will be
fixed by the next patch. ]
Daniel Déchelotte reported one problem with the escape handling in
the switchpanel:
"Start with two windows: a fullscreen one, and a smaller window
that appears above the fullscreen one. With the mouse, focus the
bigger window. Start alt-tabbing, then press Escape. The bigger
window will then be focused (good) *and raised* (small problem)."
Fix this by adding a test for the escape key before calling
raiseWindow().
Problems:
1.
During expansion of path, the resulting path can overflow the supplied
area of PATH_MAX+2 (buffer as well as buffer2). A tampered environment
variable can be used to modify program flow.
Proof:
[note: wmaker has been compiled with propolice]
$ export A="[tested with 4096x A]"
$ GNUSTEP_USER_ROOT="\$A\$A/\$A/\$A/" wmaker --for-real
*** stack smashing detected ***: wmaker terminated
Aborted
2.
Way too many functions handle a return value of NULL for wexpandpath
improperly, resulting in segfaults (and maybe other problems). To
prove the existance of these issues:
Proof:
$ GNUSTEP_USER_ROOT=~nouser wmaker --for-real
wmaker error: could not get password entry for user nouser: Success
Segmentation fault
Solution:
hard exit with error message about what is going on.
3.
The improper parsing of environment variables can lead to expansion
of path names that were not intended to be expanded.
(a) If a string like "$(var" is found, Window Maker tries to expand "var"
(environment variable) although the syntax is wrong.
Proof:
$ export PROOF=foo
$ GNUSTEP_USER_ROOT=/\$\(PROOF wmaker --for-real
wmaker warning: could not find user GNUstep directory (/foo/Defaults/WindowMaker).
(b) If the variable out of a) cannot be resolved, a closing bracket will be
added.
Proof:
$ unset PROOF
$ GNUSTEP_USER_ROOT=/\$\(PROOF wmaker --for-real
./wmaker warning: could not find user GNUstep directory ($(PROOF)/Defaults/WindowMaker).
Author: Tobias Stoeckmann
Retrieved-from: http://paldium.homeunix.org/tobias/wmaker/
Submitted-by: Gilbert Ashley <amigo@ibiblio.org>
There is no point in checking
if (dock_state)
if the function would have already returned with
the check if(!dock_state) right above.
Retrived from http://yo.dan.free.fr/wmaker.phtml.en
[crmafra: wrote the commit message]
Gcc-4.3.2 warns:
texture.c: In function 'wTextureMakeFunction':
texture.c:393: warning: 'fallbackColor.pixel' is used uninitialized in this function
Based on a patch by Vladimir Nadvornik.
Bug overview:
New windows are sometimes mis-placed when the "smart" algorithm is used.
How to reproduce it:
be sure (with WPrefs.app, for instance) to use the so-called "smart"
window placement algorithm. In an empty workspace, open a first window
(for instance, an xterm). The window should appear at the upper left corner.
Shade it (hide its contents below its title bar by double-clicking on it)
and select another empty workspace. Open another window. Instead of placing
it at the exact same place as the first window, wmaker places the new
window a little bit lower, or frankly to the right.
Explanation and correction:
when placing a new window, wmaker avoided all shaded windows, instead of
only avoiding the shaded windows on the active workspace.
1. Setup two windows in a workspace, one at the center and the
other at a corner. Move the mouse to the center of the screen, so
that the focus goes to the center window. Now, with the help of the
keyboard (with Alt-tab, typically), try and switch the focus to the
other window. In doing so, the switch panel shows up, gives the
focus to the other window and then disappears. However, its
disappearance make it seem to wmaker that the mouse has just
entered the center window, so wmaker gives the focus to that
window again.
2. It is a lit bit more involved. "Raise window when switching
focus with keyboard" needs to be set. In a given workspace, maximize
a first window A, then setup "above" window A two windows B and C
(one in the upper left corner and the other one in the lower right
corner, for example). Move the mouse so as to give the focus to
window B. Press the Alt key, hit the key tab once (window A moves
up to the "top"), then another time (window C is then selected).
Eventually relase the Alt key: window B is given the focus again.
Correction: it is a matter of ignoring some (EnterNotify) events
when the switch panel is active or has just been used.
Pressing the escape key (ESC) while the switchpanel is active
cancels it and gives the focus back to the window which had it
before the switchpanel was invoked.
If all windows are minimized before the switchpanel was called,
they will continue to be if ESC is pressed.
In other words, pressing ESC is like going to the parallel universe
where you never entered the switchpanel in the first place.
Based on a patch by Nicolas Bonifas from 17.08.2009.
This way we avoid code duplication in 6 places.
This changes the previous behavior of the first
instance because the helper function has an extra
CommitStacking(scr);
compared to the original code. But it should not
hurt to have it.
We can get rid of one overall tab by moving the
if(swpanel)
test -- which was done everytime in each individual case --
to the beginning, therefore encompassing all cases.
for arq in `git ls-files *.c`; do
echo $arq;
indent -linux -l115 $arq;
done
The different line break at 115 columns is because
I use a widescreen monitor :-)
GCC has an extension to deal with ranges within case statements.
Let's use it to make the code more readable and ~5% smaller,
[mafra@Pilar:wmaker.git]$ size src/event.o.*
text data bss dec hex filename
13087 0 1056 14143 373f src/event.o.new
13711 0 1056 14767 39af src/event.o.old
gcc-4.3.2 warns:
defaults.c: In function 'getModMask':
defaults.c:2586: warning: comparison of unsigned expression < 0 is always false
The line in question is
if (mask < 0)
and 'mask' is the return of wXModifierFromKey() which is an 'int' and can
indeed return a negative value (see src/xmodifier.c), so let 'mask' be
an 'int' too.
There is no point in having parameter in wDefaultsCheckDomains() and
not using it, so let's simply remove the parameter altogether and
avoid silly-looking things like
wDefaultsCheckDomains("bla");
gcc was complaining in a few places things like:
defaults.c:890: warning: comparison between signed and unsigned
so let's just make the loop counting variables be unsigned, as
the never get negative anyway.
I also spotted other two variables which can be unsigned too.
gcc-4.3.2 warns:
defaults.c:3136: warning: declaration of 'index' shadows a global declaration
/usr/include/string.h:309: warning: shadowed declaration is here
and in a few other places too. Fix this by renaming 'index' to 'widx'.
GCC warns:
event.c: In function 'handleDestroyNotify':
event.c:676: warning: declaration of 'index' shadows a global declaration
/usr/include/string.h:309: warning: shadowed declaration is here
event.c: In function 'handleKeyPress':
event.c:1435: warning: declaration of 'index' shadows a global declaration
/usr/include/string.h:309: warning: shadowed declaration is here
So let's rename "index" to "widx".
Note that there is a more serious shadowing in this same function,
event.c:1686: warning: declaration of 'wwin' shadows a previous local
but this is more complicated to solve.
inotifyHandleEvents() was allocating a buffer of size
(sizeof(struct inotify_event) + FILENAME_MAX)*1024
where FILENAME_MAX is #defined to be 4096 in stdio_lim.h, therefore
it was more than 4 MB!
Reduce it by using 16 instead of FILENAME_MAX and 512 instead of 1024.
Now valgrind does not complain about things like
Invalid write of size 8
at 0x42002F: inotifyHandleEvents (event.c:323)
by 0x7FF00020F: ???
Address 0x7febfc148 is on thread 1's stack
I also made some small coding style changes.
When investigating possible memory leaks with 'valgrind' I noticed
this leak report:
602 bytes in 13 blocks are definitely lost in loss record 77 of 128
at 0x4C2362E: malloc (vg_replace_malloc.c:207)
by 0x4576ED: wmalloc (memory.c:88)
by 0x45B4F7: wstrconcat (string.c:214)
by 0x426FC2: main (main.c:608)
which happens here,
str = wstrconcat("WMAKER_BIN_NAME=", argv[0]);
putenv(str);
There is a comment further below (in another context)
/* return of wstrconcat should not be free-ed! read putenv man page */
so this leak report is probably a false positive anyway. However,
https://www.securecoding.cert.org/confluence/display/seccode/POS34-C.+Do+not+call+putenv%28%29+with+a+pointer+to+an+automatic+variable+as+the+argument
has some nice discussion about putenv() and after reading it I decided to
use setenv() instead, making 'valgrind' happy along the way. It also
makes the code a bit simpler, avoiding a call to wstrconcat().
I also changed the name of another variable called 'str' to 'pos', just
in case.
This patch addresses this warning of gcc:
wfontpanel.c: In function 'listFamilies':
wfontpanel.c:588: warning: missing sentinel in function call
Fix it by using the 'NULL' pointer instead of 0 (zero) as the
sentinel.
For more information, see
http://www.linuxonly.nl/docs/2/2_GCC_4_warnings_about_sentinels.html
in particular,
"On most systems, there is no difference between 0 and (char *)0.
On 64 bit systems, however, the integer 0 is 32 bits and the
pointer 0 is 64 bits. The compiler does not know whether it is
an integer or a pointer, and defaults for the integer. This will
not clear the upper 32 bits and the function will not stop
scanning its parameters."
Note that here in my 64-bit Mandriva I don't need to cast (char *)NULL.
Based upon a patch by Tobias Stoeckmann
Small code size reduction,
text data bss dec hex filename
620412 19144 8544 648100 9e3a4 src/.libs/wmaker
621347 19152 8544 649043 9e753 src/.libs/wmaker.old
The WINGs-function wtokensplit does not set argv to NULL if no string has been
split - instead argc is set to 0.
You can only observe this issue if you compile Window Maker without any
optimization:
compile Window Maker with CFLAGS=""
run Window Maker and save a session
change session-file and replace a 'command xyz' line with 'command " "'
restart Window Maker
watch "Fatal error"-message
Retrieved-from: http://paldium.homeunix.org/tobias/wmaker/
Submitted-by: Gilbert Ashley <amigo@ibiblio.org>
This is a small patch to fix an issue with the switchpanel and a large number
of windows which happens only on a Xinerama setup.
When the number of open windows is so large that displaying all of them would
cause the switchpanel to be too wide for the screen, the panel is supposed to
shrink and scroll to accomodate them all.
In Window Maker 0.92.0 this works for single head displays but not for
Xinerama. The panel extends to the next head and gets garbled. This patch fixes
the issue by correctly constraining the panel to the head with the cursor.
Submitted-by: Gilbert Ashley <amigo@ibiblio.org>
A minor bug has been bothering me for a long time. When you maximize a
borderless window in Window Maker, the window ends up too narrow and too short
by two pixels.
Submitted-by: Gilbert Ashley <amigo@ibiblio.org>
wmaker keeps the names of all workspaces together in
the string 'buf' with fixed length of 1024, therefore
allowing buffer overflows if the number of workspaces
is big enough.
For the default names "Workspace X" (from 1 to 9)
and "Workspace XX" (from 10 to 99) etc, the approximate
number of workspaces necessary to make the buffer
overflow occur is 80, because
(11*9) + (71*12) + 80 = 1031
The fix is to set the size of 'buf' as
the maximum number of workspaces times their maximum
name length.
The problem was reported by John H. Robinson in the wmaker-dev
list ( http://lists.windowmaker.info/dev/msg00214.html ):
"http://www.youtube.com/watch?v=fkNJZvKwmhE
Michael reported a problem with Window Maker where it crashes with a
SIGSGV when trying to create an 82nd workspace.
/usr/local/WindowMaker-0.92.1pre/bin/wmaker warning: Window Maker exited
due to a crash (signal 11) and will be restarted.
I was able to reproduce it by making 81 workspaces, then creating an 82nd."
[ crmafra: Wrote the changelog ]
Actually, the whole thing is so chock full of signed vs unsigned
mixups and the assumption of all the world is 32-bit that i'm not sure
anymore that correcting them one by one is a good idea.
what would probably work best is that if someone deeply familiar with
the code (*looks in dan's general direction*) cleaned the data types
up, then legions of grunts like myself could start cleaning the rest
with relative confidence...
Here I tried to prevent the menu of windows to be displayed in the
other side of the screen if the window is half present in the screen
horizontally (ie x < 0)
a worse problem with menu is that it disappears when
the window is half present in the window vertically
ie y < 0, that makes it not usable.
This patch fixes the following warnings (with gcc 4.2.3)
defaults.c:980: warning: unused variable 'replace'
main.c:504: warning: 'watchPath' may be used uninitialized in this function
main.c:504: note: 'watchPath' was declared here
startup.c:616: warning: implicit declaration of function 'XrmUniqueQuark'
The handling of user defined shortcuts was not checking the length
of the shortcut before copying it to a fixed-length temporary buffer,
char buf[128];
strcpy(buf, shortcutDefinition);
and strcpy() is well known for not checking if overflows will occur.
In particular, wmaker was crashing here if a big 'shortcut' was defined
either through WPrefs or by directly editing the configuration files.
This is now avoided by using strncpy() instead.
And this patch also fixes a similar buffer overflow for big workspace
names too.
Furthermore, use MAX_SHORTCUT_LENGTH instead of raw number and define
it to be 32 instead of 128.
There may be issues with running applications in 64-bit mode when
they were written with tacit assumptions about 32-bit platforms.
For example,
* Assuming that a pointer can be cast back and forth to an integer
The reason is that the size of the integer and pointer may be different.
See the description of "[PATCH] Warn when casting a pointer (constant)
to an integer of different size." in the gcc mailing list
http://gcc.gnu.org/ml/gcc-patches/2005-12/msg01881.html
where it was also suggested the use of casts to uintptr_t. This is
what this patch does.
As a result the following warnings are fixed, leaving us with an
almost warning-free compilation in 64-bit platforms:
defaults.c:1446: warning: cast to pointer from integer of different size
defaults.c:1457: warning: cast to pointer from integer of different size
defaults.c:1471: warning: cast to pointer from integer of different size
defaults.c:1486: warning: cast to pointer from integer of different size
icon.c:67: warning: cast from pointer to integer of different size
menu.c:112: warning: cast from pointer to integer of different size
switchmenu.c:452: warning: cast from pointer to integer of different size
window.c:140: warning: cast from pointer to integer of different size
window.c:2217: warning: cast to pointer from integer of different size
workspace.c:135: warning: cast to pointer from integer of different size
workspace.c:214: warning: cast to pointer from integer of different size
workspace.c:634: warning: cast to pointer from integer of different size
workspace.c:1330: warning: cast to pointer from integer of different size
workspace.c:1514: warning: cast to pointer from integer of different size
wfilepanel.c:135: warning: cast from pointer to integer of different size
wfilepanel.c:171: warning: cast from pointer to integer of different size
wfontpanel.c:499: warning: cast to pointer from integer of different size
wfontpanel.c:500: warning: cast to pointer from integer of different size
wfontpanel.c:505: warning: cast to pointer from integer of different size
wfontpanel.c:506: warning: cast to pointer from integer of different size
wfontpanel.c:776: warning: cast from pointer to integer of different size
wfontpanel.c:777: warning: cast from pointer to integer of different size
wfontpanel.c:877: warning: cast from pointer to integer of different size
wfontpanel.c:878: warning: cast from pointer to integer of different size
wpanel.c:363: warning: cast from pointer to integer of different size
fontl.c:42: warning: cast from pointer to integer of different size
fontl.c:42: warning: cast from pointer to integer of different size
fontl.c:42: warning: cast from pointer to integer of different size
fontl.c:90: warning: cast to pointer from integer of different size
puzzle.c:138: warning: cast from pointer to integer of different size
puzzle.c:225: warning: cast to pointer from integer of different size
wtableview.c:1031: warning: cast to pointer from integer of different size
wtableview.c:1067: warning: cast to pointer from integer of different size
wtableview.c:1069: warning: cast to pointer from integer of different size
wtableview.c:1074: warning: cast to pointer from integer of different size
wtabledelegates.c:234: warning: cast from pointer to integer of different size
wtabledelegates.c:250: warning: cast from pointer to integer of different size
wtabledelegates.c:265: warning: cast from pointer to integer of different size
wtabledelegates.c:287: warning: cast to pointer from integer of different size
wtabledelegates.c:351: warning: cast from pointer to integer of different size
wtabledelegates.c:372: warning: cast from pointer to integer of different size
wtabledelegates.c:393: warning: cast from pointer to integer of different size
wtabledelegates.c:410: warning: cast to pointer from integer of different size
test.c:44: warning: cast from pointer to integer of different size
test.c:47: warning: cast to pointer from integer of different size
test.c:55: warning: cast from pointer to integer of different size
test.c:58: warning: cast from pointer to integer of different size