mirror of
https://github.com/systemd/systemd.git
synced 2024-10-31 07:51:21 +03:00
basic/escape: use _cleanup_ in one more place
Also, let's not use 'r' for a char*.
This commit is contained in:
parent
fe819f569a
commit
ddedf7ca69
@ -289,9 +289,11 @@ int cunescape_one(const char *p, size_t length, char32_t *ret, bool *eight_bit,
|
||||
}
|
||||
|
||||
int cunescape_length_with_prefix(const char *s, size_t length, const char *prefix, UnescapeFlags flags, char **ret) {
|
||||
char *r, *t;
|
||||
_cleanup_free_ char *ans = NULL;
|
||||
char *t;
|
||||
const char *f;
|
||||
size_t pl;
|
||||
int r;
|
||||
|
||||
assert(s);
|
||||
assert(ret);
|
||||
@ -300,18 +302,17 @@ int cunescape_length_with_prefix(const char *s, size_t length, const char *prefi
|
||||
|
||||
pl = strlen_ptr(prefix);
|
||||
|
||||
r = new(char, pl+length+1);
|
||||
if (!r)
|
||||
ans = new(char, pl+length+1);
|
||||
if (!ans)
|
||||
return -ENOMEM;
|
||||
|
||||
if (prefix)
|
||||
memcpy(r, prefix, pl);
|
||||
memcpy(ans, prefix, pl);
|
||||
|
||||
for (f = s, t = r + pl; f < s + length; f++) {
|
||||
for (f = s, t = ans + pl; f < s + length; f++) {
|
||||
size_t remaining;
|
||||
bool eight_bit = false;
|
||||
char32_t u;
|
||||
int k;
|
||||
|
||||
remaining = s + length - f;
|
||||
assert(remaining > 0);
|
||||
@ -329,23 +330,21 @@ int cunescape_length_with_prefix(const char *s, size_t length, const char *prefi
|
||||
continue;
|
||||
}
|
||||
|
||||
free(r);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
k = cunescape_one(f + 1, remaining - 1, &u, &eight_bit, flags & UNESCAPE_ACCEPT_NUL);
|
||||
if (k < 0) {
|
||||
r = cunescape_one(f + 1, remaining - 1, &u, &eight_bit, flags & UNESCAPE_ACCEPT_NUL);
|
||||
if (r < 0) {
|
||||
if (flags & UNESCAPE_RELAX) {
|
||||
/* Invalid escape code, let's take it literal then */
|
||||
*(t++) = '\\';
|
||||
continue;
|
||||
}
|
||||
|
||||
free(r);
|
||||
return k;
|
||||
return r;
|
||||
}
|
||||
|
||||
f += k;
|
||||
f += r;
|
||||
if (eight_bit)
|
||||
/* One byte? Set directly as specified */
|
||||
*(t++) = u;
|
||||
@ -356,8 +355,8 @@ int cunescape_length_with_prefix(const char *s, size_t length, const char *prefi
|
||||
|
||||
*t = 0;
|
||||
|
||||
*ret = r;
|
||||
return t - r;
|
||||
*ret = TAKE_PTR(ans);
|
||||
return t - *ret;
|
||||
}
|
||||
|
||||
char* xescape_full(const char *s, const char *bad, size_t console_width, XEscapeFlags flags) {
|
||||
|
Loading…
Reference in New Issue
Block a user