mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 20:38:08 +01:00
As coverity found a number of problem in the code, a few changes are made to the function: - allocate better sizes for the strings (the original code allocated too much room in many cases and missed the room for the final '\0' in a case) - do not free strings if empty anymore (the actual check was not correct anyway), but avoid allocating in first place if it is not necessary. Signed-off-by: Christophe CURIS <christophe.curis@free.fr> Signed-off-by: Carlos R. Mafra <crmafra@gmail.com>
This commit is contained in:
committed by
Carlos R. Mafra
parent
ac3212b001
commit
d726eaf617
48
src/misc.c
48
src/misc.c
@@ -862,16 +862,14 @@ char *EscapeWM_CLASS(const char *name, const char *class)
|
||||
static void UnescapeWM_CLASS(const char *str, char **name, char **class)
|
||||
{
|
||||
int i, j, k, dot;
|
||||
int length_of_name;
|
||||
|
||||
j = strlen(str);
|
||||
*name = wmalloc(j);
|
||||
**name = 0;
|
||||
*class = wmalloc(j);
|
||||
**class = 0;
|
||||
|
||||
/* separate string in 2 parts */
|
||||
length_of_name = 0;
|
||||
dot = -1;
|
||||
for (i = 0; i < j; i++) {
|
||||
for (i = 0; i < j; i++, length_of_name++) {
|
||||
if (str[i] == '\\') {
|
||||
i++;
|
||||
continue;
|
||||
@@ -881,31 +879,27 @@ static void UnescapeWM_CLASS(const char *str, char **name, char **class)
|
||||
}
|
||||
}
|
||||
|
||||
/* unescape strings */
|
||||
for (i = 0, k = 0; i < dot; i++) {
|
||||
if (str[i] == '\\') {
|
||||
continue;
|
||||
} else {
|
||||
(*name)[k++] = str[i];
|
||||
/* unescape the name */
|
||||
if (length_of_name > 0) {
|
||||
*name = wmalloc(length_of_name + 1);
|
||||
for (i = 0, k = 0; i < dot; i++) {
|
||||
if (str[i] != '\\')
|
||||
(*name)[k++] = str[i];
|
||||
}
|
||||
}
|
||||
(*name)[k] = 0;
|
||||
|
||||
for (i = dot + 1, k = 0; i < j; i++) {
|
||||
if (str[i] == '\\') {
|
||||
continue;
|
||||
} else {
|
||||
(*class)[k++] = str[i];
|
||||
}
|
||||
}
|
||||
(*class)[k] = 0;
|
||||
|
||||
if (!*name) {
|
||||
wfree(*name);
|
||||
(*name)[k] = '\0';
|
||||
} else {
|
||||
*name = NULL;
|
||||
}
|
||||
if (!*class) {
|
||||
wfree(*class);
|
||||
|
||||
/* unescape the class */
|
||||
if (dot < j-1) {
|
||||
*class = wmalloc(j - (dot + 1) + 1);
|
||||
for (i = dot + 1, k = 0; i < j; i++) {
|
||||
if (str[i] != '\\')
|
||||
(*class)[k++] = str[i];
|
||||
}
|
||||
(*class)[k] = 0;
|
||||
} else {
|
||||
*class = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user