Skip to content

Commit 98a33e4

Browse files
authored
Topic silence warnings (#364)
* 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * fix memory leak in mousemove, mousedown window_arg was strdup()ed but not freed, fix that. Signed-off-by: Bernhard Reutner-Fischer <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * xdotool: Remove redundant declarations These live in xdo_cmd.h so are redundant in xdotool.c Signed-off-by: Bernhard Reutner-Fischer <[email protected]> * 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 <[email protected]>
1 parent 5401457 commit 98a33e4

12 files changed

+136
-109
lines changed

Diff for: cmd_behave.c

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ struct events {
1313
{ NULL, 0 },
1414
};
1515

16-
/* So we can invoke xdotool from within this command */
17-
extern int context_execute(context_t *context);
18-
1916
int cmd_behave(context_t *context) {
2017
int ret = 0;
2118
char *cmd = *context->argv;

Diff for: cmd_behave_screen_edge.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,7 @@ int cmd_behave_screen_edge(context_t *context) {
304304
} /* if quiesce */
305305
} /* if trigger == True */
306306

307-
if (tmpcontext != NULL) {
308-
free(tmpcontext);
309-
}
307+
free(tmpcontext);
310308

311309
if (ret != XDO_SUCCESS) {
312310
printf("Command failed.\n");

Diff for: cmd_exec.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ int cmd_exec(context_t *context) {
116116
}
117117

118118
consume_args(context, command_count);
119-
if (terminator != NULL) {
120-
free(terminator);
121-
}
119+
free(terminator);
122120

123121
for (i=0; i < command_count; i++) {
124122
free(command[i]);

Diff for: cmd_mousedown.c

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ int cmd_mousedown(context_t *context) {
7373
}); /* window_each(...) */
7474

7575
consume_args(context, 1);
76+
free(window_arg);
7677

7778
return ret;
7879
}

Diff for: cmd_mousemove.c

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ int cmd_mousemove(context_t *context) {
131131
}
132132
}); /* window_each(...) */
133133

134+
free(window_arg);
135+
134136
return ret;
135137
}
136138

Diff for: cmd_mouseup.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ int cmd_mouseup(context_t *context) {
7272
}
7373
}); /* window_each(...) */
7474

75-
if (window_arg != NULL) {
76-
free(window_arg);
77-
}
75+
free(window_arg);
7876
consume_args(context, 1);
7977
return ret;
8078
}

Diff for: cmd_search.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,7 @@ int cmd_search(context_t *context) {
190190
}
191191

192192
do {
193-
if (list != NULL) {
194-
free(list);
195-
}
193+
free(list);
196194

197195
xdo_search_windows(context->xdo, &search, &list, &nwindows);
198196

@@ -214,9 +212,7 @@ int cmd_search(context_t *context) {
214212
} while (op_sync && nwindows == 0);
215213

216214
/* Free old list as it's malloc'd by xdo_search_windows */
217-
if (context->windows != NULL) {
218-
free(context->windows);
219-
}
215+
free(context->windows);
220216
context->windows = list;
221217
context->nwindows = nwindows;
222218

Diff for: xdo.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,8 @@ void xdo_free(xdo_t *xdo) {
160160
if (xdo == NULL)
161161
return;
162162

163-
if (xdo->display_name)
164-
free(xdo->display_name);
165-
if (xdo->charcodes)
166-
free(xdo->charcodes);
163+
free(xdo->display_name);
164+
free(xdo->charcodes);
167165
if (xdo->xdpy && xdo->close_display_when_freed)
168166
XCloseDisplay(xdo->xdpy);
169167

@@ -1038,9 +1036,7 @@ int _xdo_send_keysequence_window_do(const xdo_t *xdo, Window window, const char
10381036
}
10391037

10401038
ret = xdo_send_keysequence_window_list_do(xdo, window, keys, nkeys, pressed, modifier, delay);
1041-
if (keys != NULL) {
1042-
free(keys);
1043-
}
1039+
free(keys);
10441040

10451041
return ret;
10461042
}
@@ -1936,12 +1932,16 @@ int xdo_get_window_name(const xdo_t *xdo, Window window,
19361932
return 0;
19371933
}
19381934

1939-
int xdo_get_window_classname(const xdo_t *xdo, Window window, unsigned char **name_ret) {
1935+
int xdo_get_window_classname(const xdo_t *xdo, Window window, unsigned char **class_ret) {
19401936
XClassHint classhint;
1941-
XGetClassHint(xdo->xdpy, window, &classhint);
1942-
XFree(classhint.res_name);
1943-
*name_ret = (unsigned char*) classhint.res_class;
1944-
return 0;
1937+
Status ret = XGetClassHint(xdo->xdpy, window, &classhint);
1938+
1939+
if (ret) {
1940+
XFree(classhint.res_name);
1941+
*class_ret = (unsigned char*) classhint.res_class;
1942+
} else
1943+
*class_ret = NULL;
1944+
return _is_success("XGetClassHint[WM_CLASS]", ret == 0, xdo);
19451945
}
19461946

19471947
int xdo_window_state(xdo_t *xdo, Window window, unsigned long action, const char *property) {
@@ -2058,4 +2058,4 @@ static int appears_to_be_wayland(Display *xdpy) {
20582058
XFreeDeviceList(devices);
20592059

20602060
return 0;
2061-
}
2061+
}

Diff for: xdo.h

+7
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,13 @@ int xdo_minimize_window(const xdo_t *xdo, Window wid);
618618
#define _NET_WM_STATE_ADD 1 /* add/set property */
619619
#define _NET_WM_STATE_TOGGLE 2 /* toggle property */
620620

621+
/**
622+
* Get window classname
623+
* @param window the window
624+
* @param class_ret Pointer to the window classname WM_CLASS
625+
*/
626+
int xdo_get_window_classname(const xdo_t *xdo, Window window, unsigned char **class_ret);
627+
621628
/**
622629
* Change window state
623630
* @param action the _NET_WM_STATE action

Diff for: xdo_cmd.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ extern void window_list(context_t *context, const char *window_arg,
3232
extern void window_save(context_t *context, Window window);
3333
extern int is_command(char *cmd);
3434

35-
extern int window_is_valid(context_t *context, const char *window_arg);
3635
extern int window_get_arg(context_t *context, int min_arg, int window_arg_pos,
3736
const char **window_arg);
3837

38+
extern int context_execute(context_t *);
39+
3940
extern void xdotool_debug(context_t *context, const char *format, ...);
4041
extern void xdotool_output(context_t *context, const char *format, ...);
4142

0 commit comments

Comments
 (0)