mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
spa: deal with non-null terminated strings in spa_error_location
Add len field to indicate number of valid characters after location.
This commit is contained in:
parent
a0af514581
commit
3e99a0e839
3 changed files with 3 additions and 1 deletions
|
|
@ -38,7 +38,7 @@ static inline void spa_debugc_error_location(struct spa_debug_context *c,
|
||||||
int i, skip = loc->col > 80 ? loc->col - 40 : 0, lc = loc->col-skip-1;
|
int i, skip = loc->col > 80 ? loc->col - 40 : 0, lc = loc->col-skip-1;
|
||||||
char buf[80];
|
char buf[80];
|
||||||
|
|
||||||
for (i = 0; (size_t)i < sizeof(buf)-1; i++) {
|
for (i = 0; (size_t)i < sizeof(buf)-1 && (size_t)(i + skip) < loc->len; i++) {
|
||||||
char ch = loc->location[i + skip];
|
char ch = loc->location[i + skip];
|
||||||
if (ch == '\n' || ch == '\0')
|
if (ch == '\n' || ch == '\0')
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -330,6 +330,7 @@ static inline bool spa_ptr_inside_and_aligned(const void *p1, size_t s1,
|
||||||
struct spa_error_location {
|
struct spa_error_location {
|
||||||
int line;
|
int line;
|
||||||
int col;
|
int col;
|
||||||
|
size_t len;
|
||||||
const char *location;
|
const char *location;
|
||||||
const char *reason;
|
const char *reason;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -350,6 +350,7 @@ static inline bool spa_json_get_error(struct spa_json *iter, const char *start,
|
||||||
loc->line = linepos;
|
loc->line = linepos;
|
||||||
loc->col = colpos;
|
loc->col = colpos;
|
||||||
loc->location = l;
|
loc->location = l;
|
||||||
|
loc->len = SPA_PTRDIFF(iter->end, loc->location) / sizeof(char);
|
||||||
loc->reason = code == 0 ? strerror(errno) : reasons[code];
|
loc->reason = code == 0 ? strerror(errno) : reasons[code];
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue