1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
--- src/user.c.orig Fri Nov 29 09:03:53 2002
+++ src/user.c Tue Jun 15 03:15:09 2004
@@ -138,19 +138,14 @@
}
/* Copy the variable name */
- var_name = g_malloc (dots - p);
- strncpy (var_name, p+4, dots-2 - (p+3));
- var_name [dots-2 - (p+3)] = 0;
-
+ var_name = g_strndup (p + 4, dots - p - 5);
value = getenv (var_name);
g_free (var_name);
if (value){
*v = g_strdup (value);
return q-p;
}
- var_name = g_malloc (q - dots + 1);
- strncpy (var_name, dots, q - dots + 1);
- var_name [q-dots] = 0;
+ var_name = g_strndup (dots, q - dots);
*v = var_name;
return q-p;
}
@@ -300,13 +295,15 @@
/* Copies a whitespace separated argument from p to arg. Returns the
point after argument. */
-static char *extract_arg (char *p, char *arg)
+static char *extract_arg (char *p, char *arg, size_t size)
{
while (*p && (*p == ' ' || *p == '\t' || *p == '\n'))
p++;
/* support quote space .mnu */
- while (*p && (*p != ' ' || *(p-1) == '\\') && *p != '\t' && *p != '\n')
+ while (size > 1 && *p && (*p != ' ' || *(p-1) == '\\') && *p != '\t' && *p != '\n') {
*arg++ = *p++;
+ size--;
+ }
*arg = 0;
if (!*p || *p == '\n')
p --;
@@ -389,29 +386,29 @@
p--;
break;
case 'f': /* file name pattern */
- p = extract_arg (p, arg);
+ p = extract_arg (p, arg, sizeof (arg));
*condition = panel && regexp_match (arg, panel->dir.list [panel->selected].fname, match_file);
break;
case 'y': /* syntax pattern */
if (edit_widget && edit_widget->syntax_type) {
- p = extract_arg (p, arg);
+ p = extract_arg (p, arg, sizeof (arg));
*condition = panel &&
regexp_match (arg, edit_widget->syntax_type, match_normal);
}
break;
case 'd':
- p = extract_arg (p, arg);
+ p = extract_arg (p, arg, sizeof (arg));
*condition = panel && regexp_match (arg, panel->cwd, match_file);
break;
case 't':
- p = extract_arg (p, arg);
+ p = extract_arg (p, arg, sizeof (arg));
*condition = panel && test_type (panel, arg);
break;
case 'x': /* executable */
{
struct stat status;
- p = extract_arg (p, arg);
+ p = extract_arg (p, arg, sizeof (arg));
if (stat (arg, &status) == 0)
*condition = is_exe (status.st_mode);
else
@@ -431,50 +428,43 @@
static void
debug_out (char *start, char *end, int cond)
{
- static char msg [256];
+ static char *msg;
int len;
if (start == NULL && end == NULL){
- if (cond == 0){
- /* Init */
- msg [0] = 0;
- } else {
- /* Show output */
- if (!debug_flag)
- return;
+ /* Show output */
+ if (debug_flag && msg) {
len = strlen (msg);
if (len)
msg [len - 1] = 0;
message (0, _(" Debug "), "%s", msg);
- debug_flag = 0;
}
+ debug_flag = 0;
+ g_free (msg);
+ msg = NULL;
} else {
+ char *type, *p;
+
/* Save debug info for later output */
if (!debug_flag)
return;
/* Save the result of the condition */
if (debug_error){
- strcat (msg, _(" ERROR: "));
+ type = _(" ERROR: ");
debug_error = 0;
}
else if (cond)
- strcat (msg, _(" True: "));
+ type = _(" True: ");
else
- strcat (msg, _(" False: "));
- /* Copy condition statement */
- len = strlen (msg);
- if (end == NULL){
- /* Copy one character */
- msg [len] = *start;
- msg [len + 1] = 0;
- } else {
- /* Copy many characters */
- while (start < end){
- msg [len++] = *start++;
- }
- msg [len] = 0;
- }
- strcat (msg, " \n");
+ type = _(" False: ");
+ /* This is for debugging, don't need to be super efficient. */
+ if (end == NULL)
+ p = g_strdup_printf ("%s%s%c \n", msg ? msg : "", type, *start);
+ else
+ p = g_strdup_printf ("%s%s%.*s \n", msg ? msg : "", type,
+ (int) (end - start), start);
+ g_free (msg);
+ msg = p;
}
}
@@ -486,8 +476,6 @@
char operator;
char *debug_start, *debug_end;
- /* Init debugger */
- debug_out (NULL, NULL, 0);
/* Repeat till end of line */
while (*p && *p != '\n') {
/* support quote space .mnu */
@@ -578,6 +566,8 @@
break;
while (*commands == ' ' || *commands == '\t')
commands++;
+ if (*commands == '0')
+ break;
}
col++;
if (*commands == '\n')
@@ -734,7 +724,7 @@
} else if (*p == '+'){
if (*(p+1) == '='){
/* Combined adding and default */
- p = test_line (edit_widget, p, &accept_entry);
+ p = test_line (edit_widget, p + 1, &accept_entry);
if (selected == 0 && accept_entry)
selected = menu_lines;
} else {
@@ -744,7 +734,7 @@
} else if (*p == '='){
if (*(p+1) == '+'){
/* Combined adding and default */
- p = test_line (edit_widget, p, &accept_entry);
+ p = test_line (edit_widget, p + 1, &accept_entry);
if (selected == 0 && accept_entry)
selected = menu_lines;
} else {
|