Skip to content

Topic silence warnings#364

Merged
jordansissel merged 9 commits intojordansissel:masterfrom
aldot:topic-silence-warnings
Oct 24, 2021
Merged

Topic silence warnings#364
jordansissel merged 9 commits intojordansissel:masterfrom
aldot:topic-silence-warnings

Conversation

@aldot
Copy link
Contributor

@aldot aldot commented Oct 21, 2021

Silence some warnings.
Thanks!

aldot added 9 commits October 21, 2021 13:12
italic does not work in verbatim paragraphs, remove it:
 sed -i -e 's/^\(  *.*\)I</\1</g' xdotool.pod

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
.. when allocating space for tokens while parsing.
The array allocation was checked already, also check that allocating
memory for the content works out fine.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
I was getting 'Unknown command: <garbage-on-stack>' for a sequence of
commands that containted no newline:
echo -n "several commands and args here" | xdotool -

fgets null-terminates the buffer, but we were tokenizing past the end of
the read line in the while-loop since we skipped the _final_ zero byte.

There was another bug when tokenizing the commandline arguments when
one token spans more than one buffer, the token was seen as two arguments,
cut in half mid-word where the previous buffer ended and the new buffer
started. E.g.: printf "mousemove%-4083s--polar -- 0 0" " "
complained that "Unknown command: olar".
Another incarnation of the same bug could be observed if you fed a token
into script_main that was longer than the buffer size: It was split on
the buffer boundary, making several tokens out of the single token given
by the user. E.g.:
 perl -le 'print(("X"x 9000))' > input-9000
or
 python3 -c 'print("X" * 9000)' > input-9000
and looking at the script argv when cat input-9000 | xdotool -

Or printf "mousemove%4107s" "--polar -- 0 0 sleep 0.1" > /tmp/i
(cat /tmp/i;echo " sleep 4";echo mousemove --polar -- 30 30) | ./xdotool -

Fix this by correctly handling tokens that cross buffers.

Diagnose allocation failures while at it.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
window_arg was strdup()ed but not freed, fix that.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
SUS specifies that free(NULL) is perfectly valid (a noop).
Remove superfluous guards.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
This is a private helper-function of window_get_arg() and not used
anywhere else.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
and remove now redundant declarations.
A single declaration avoids the risk of diverging scattered
declarations.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
These live in xdo_cmd.h so are redundant in xdotool.c

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
1) warning: no previous prototype for ‘xdo_get_window_classname’
2) warning: pointer targets in assignment from ‘char *’ to ‘unsigned char *’ differ in signedness
   for classhint.res_class

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Copy link
Owner

@jordansissel jordansissel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment: There several commits that make what seem to be unrelated changes. Combine this with the PR subject "Topic silence warnings" with almost no information in the PR description, and it feels like not enough detail.

In the future, I'd love to see more details about the intent of the change (silence what warnings? When do the warnings show up? How do these changes improve things? etc).

That said, I do like the code cleanup, thank you!

I will also test the script changes before merging.

@jordansissel
Copy link
Owner

I wrote a test case for the script buffer changes 👍

@jordansissel jordansissel merged commit 98a33e4 into jordansissel:master Oct 24, 2021
jordansissel added a commit that referenced this pull request Oct 24, 2021
Where "long" means longer than the script buffer size which, at this
time, is 4096 bytes.

Verified this test case fails prior to #364 being merged and succeeds
after.
@jordansissel
Copy link
Owner

Added a test case: a3f4994

@aldot
Copy link
Contributor Author

aldot commented Oct 24, 2021

General comment: There several commits that make what seem to be unrelated changes. Combine this with the PR subject "Topic silence warnings" with almost no information in the PR description, and it feels like not enough detail.

These were meant to be 3 distinct patchsets.
#270 (script_main fixes)
#364 (silence warnings, tweak declarations)
#365 (fix memory leaks)

If you checkout https://github.com/aldot/xdotool.git and look at the history via
gitk --all
gitg --all
git log --graph --decorate --source --all --oneline
the picture should be clear.

In the future, I'd love to see more details about the intent of the change (silence what warnings? When do the warnings show up? How do these changes improve things? etc).

The 4 "silence warnings" patches are:
(origin/topic-silence-warnings) getwindowclassname: silence warning
xdotool: Remove redundant declarations
context_execute(): Move prototype to xdo_cmd.h
window_is_valid(): make static

and should each contain a rational for the change.
I admit that only the "getwindowclassname: silence warning" really does silence a warning :-/
The other 3 are cleanups of declarations or making an internal helper static.

That said, I do like the code cleanup, thank you!

I will also test the script changes before merging.

You're welcome.
Please let me know if you want me to shuffle around hunks or expand a commit message, of course!
thanks,

@aldot
Copy link
Contributor Author

aldot commented Oct 24, 2021

Added a test case: a3f4994

Another good test would be to span an argument to the next buffer:
$ printf "mousemove%4107s" "--polar -- 0 0 sleep 0.1" | DEBUG=1 ./xdotool -
command: mousemove
command: sleep

is the expected behaviour.
Previously we tried to run "mousemove --p" which errored out due to a malformed command

I think that would be a good testcase; If you don't like sleep the any other command will of course do to demonstrate the issue.

buldi pushed a commit to buldi/xdotool that referenced this pull request Apr 23, 2022
* xdotool.1: Fix rendering of example commands

italic does not work in verbatim paragraphs, remove it:
 sed -i -e 's/^\(  *.*\)I</\1</g' xdotool.pod

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>

* Error out on allocation failure

.. when allocating space for tokens while parsing.
The array allocation was checked already, also check that allocating
memory for the content works out fine.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>

* Fix tokenizing a single-line command chain

I was getting 'Unknown command: <garbage-on-stack>' for a sequence of
commands that containted no newline:
echo -n "several commands and args here" | xdotool -

fgets null-terminates the buffer, but we were tokenizing past the end of
the read line in the while-loop since we skipped the _final_ zero byte.

There was another bug when tokenizing the commandline arguments when
one token spans more than one buffer, the token was seen as two arguments,
cut in half mid-word where the previous buffer ended and the new buffer
started. E.g.: printf "mousemove%-4083s--polar -- 0 0" " "
complained that "Unknown command: olar".
Another incarnation of the same bug could be observed if you fed a token
into script_main that was longer than the buffer size: It was split on
the buffer boundary, making several tokens out of the single token given
by the user. E.g.:
 perl -le 'print(("X"x 9000))' > input-9000
or
 python3 -c 'print("X" * 9000)' > input-9000
and looking at the script argv when cat input-9000 | xdotool -

Or printf "mousemove%4107s" "--polar -- 0 0 sleep 0.1" > /tmp/i
(cat /tmp/i;echo " sleep 4";echo mousemove --polar -- 30 30) | ./xdotool -

Fix this by correctly handling tokens that cross buffers.

Diagnose allocation failures while at it.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>

* fix memory leak in mousemove, mousedown

window_arg was strdup()ed but not freed, fix that.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>

* Remove superfluous guards around free(NULL)

SUS specifies that free(NULL) is perfectly valid (a noop).
Remove superfluous guards.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>

* window_is_valid(): make static

This is a private helper-function of window_get_arg() and not used
anywhere else.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>

* context_execute(): Move prototype to xdo_cmd.h

and remove now redundant declarations.
A single declaration avoids the risk of diverging scattered
declarations.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>

* xdotool: Remove redundant declarations

These live in xdo_cmd.h so are redundant in xdotool.c

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>

* getwindowclassname: silence warning

1) warning: no previous prototype for ‘xdo_get_window_classname’
2) warning: pointer targets in assignment from ‘char *’ to ‘unsigned char *’ differ in signedness
   for classhint.res_class

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
buldi pushed a commit to buldi/xdotool that referenced this pull request Apr 23, 2022
Where "long" means longer than the script buffer size which, at this
time, is 4096 bytes.

Verified this test case fails prior to jordansissel#364 being merged and succeeds
after.
@aldot aldot deleted the topic-silence-warnings branch May 4, 2023 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants