path.c: dirname_s: allow 'path' to point to the static buffer.
feeding the function a pointer to sb.buf results in path also being cleared by the call to strbuf_reduce and the information is lost.
This commit is contained in:
parent
3c2436867e
commit
a1a85267f0
2 changed files with 9 additions and 3 deletions
|
|
@ -85,9 +85,11 @@ int path_isparent(const char *path, const char *parent) {
|
|||
const char* dirname_s(const char *path, int slash) {
|
||||
|
||||
static strbuf_t sb = STRBUF_INIT;
|
||||
|
||||
strbuf_reduce(&sb, sb.len);
|
||||
strbuf_append_str(&sb, path);
|
||||
|
||||
if (sb.buf != path) {
|
||||
strbuf_setlen(&sb, 0);
|
||||
strbuf_append_str(&sb, path);
|
||||
}
|
||||
strbuf_squeeze(&sb, '/');
|
||||
|
||||
if (sb.len > 1) {
|
||||
|
|
|
|||
Reference in a new issue