size_t len = strlen(abs) + 1;
int copy_relative = strcmp(relative_buf, ".") != 0;
int mid = copy_relative && abs[0] != 0;
- char *new_cwd = malloc(len + (copy_relative ? strlen(relative_buf) + mid: 0));
+ char *new_cwd = malloc(len + (copy_relative ? strlen(relative_buf) + mid: 0)+1);
if (new_cwd == NULL) {
errno = ENOMEM;
return -1;
new_cwd[0] = '/';
strcpy(new_cwd + 1, abs);
if (mid)
- new_cwd[strlen(abs) + 1] = '/';
+ new_cwd[len] = '/';
if (copy_relative)
strcpy(new_cwd + 1 + mid + strlen(abs), relative_buf);
int need_slash = __wasilibc_cwd[cwd_len - 1] == '/' ? 0 : 1;
size_t alloc_len = cwd_len + path_len + 1 + need_slash;
if (alloc_len > make_absolute_len) {
- make_absolute_buf = realloc(make_absolute_buf, alloc_len);
- if (make_absolute_buf == NULL)
+ char *tmp = realloc(make_absolute_buf, alloc_len);
+ if (tmp == NULL)
return NULL;
+ make_absolute_buf = tmp;
make_absolute_len = alloc_len;
}
strcpy(make_absolute_buf, __wasilibc_cwd);