/*
* Append a name to the current dir path.
*/
-static void
+static int
tree_append(struct tree *t, const wchar_t *name, size_t name_length)
{
size_t size_needed;
/* Resize pathname buffer as needed. */
size_needed = name_length + t->dirname_length + 2;
- archive_wstring_ensure(&t->path, size_needed);
+ if (archive_wstring_ensure(&t->path, size_needed) == NULL)
+ return (TREE_ERROR_FATAL);
/* Add a separating '/' if it's needed. */
if (t->dirname_length > 0 &&
t->path.s[archive_strlen(&t->path)-1] != L'/')
t->full_path.s[t->full_path_dir_length] = L'\0';
t->full_path.length = t->full_path_dir_length;
size_needed = name_length + t->full_path_dir_length + 2;
- archive_wstring_ensure(&t->full_path, size_needed);
+ if (archive_wstring_ensure(&t->full_path, size_needed) == NULL)
+ return (TREE_ERROR_FATAL);
/* Add a separating '\' if it's needed. */
if (t->full_path.s[archive_strlen(&t->full_path)-1] != L'\\')
archive_wstrappend_wchar(&t->full_path, L'\\');
archive_wstrncat(&t->full_path, name, name_length);
t->restore_time.full_path = t->full_path.s;
}
+ return (0);
}
/*
t = calloc(1, sizeof(*t));
archive_string_init(&(t->full_path));
archive_string_init(&t->path);
- archive_wstring_ensure(&t->path, 15);
+ if (archive_wstring_ensure(&t->path, 15) == NULL) {
+ free(t);
+ return (NULL);
+ }
t->initial_symlink_mode = symlink_mode;
return (tree_reopen(t, path, restore_time));
}
p = wcsrchr(base, L'/');
if (p != NULL) {
*p = L'\0';
- tree_append(t, base, p - base);
+ if (tree_append(t, base, p - base))
+ goto failed;
t->dirname_length = archive_strlen(&t->path);
base = p + 1;
}
}
/* Top stack item needs a regular visit. */
t->current = t->stack;
- tree_append(t, t->stack->name.s,
+ r = tree_append(t, t->stack->name.s,
archive_strlen(&(t->stack->name)));
+ if (r != 0)
+ return (r);
//t->dirname_length = t->path_length;
//tree_pop(t);
t->stack->flags &= ~needsFirstVisit;
} else if (t->stack->flags & needsDescent) {
/* Top stack item is dir to descend into. */
t->current = t->stack;
- tree_append(t, t->stack->name.s,
+ r = tree_append(t, t->stack->name.s,
archive_strlen(&(t->stack->name)));
+ if (r != 0)
+ return (r);
t->stack->flags &= ~needsDescent;
r = tree_descent(t);
if (r != 0) {
struct archive_wstring pt;
archive_string_init(&pt);
- archive_wstring_ensure(&pt,
+ if (archive_wstring_ensure(&pt,
archive_strlen(&(t->full_path))
- + 2 + wcslen(pattern));
+ + 2 + wcslen(pattern)) == NULL)
+ return (TREE_ERROR_FATAL);
archive_wstring_copy(&pt, &(t->full_path));
archive_wstrappend_wchar(&pt, L'\\');
archive_wstrcat(&pt, pattern);
continue;
if (name[0] == L'.' && name[1] == L'.' && name[2] == L'\0')
continue;
- tree_append(t, name, namelen);
+ r = tree_append(t, name, namelen);
+ if (r != 0)
+ return (r);
return (t->visit_type = TREE_REGULAR);
}
}
wn = _wcsdup(wnp);
if (wn == NULL)
return (-1);
- archive_wstring_ensure(&(a->_name_data), 4 + wcslen(wn) + 1);
+ if (archive_wstring_ensure(&(a->_name_data),
+ 4 + wcslen(wn) + 1) == NULL) {
+ free(wn);
+ return (-1);
+ }
a->name = a->_name_data.s;
/* Prepend "\\?\" */
archive_wstrncpy(&(a->_name_data), L"\\\\?\\", 4);
wn = _wcsdup(wnp);
if (wn == NULL)
return (-1);
- archive_wstring_ensure(&(a->_name_data),
- 8 + wcslen(wn) + 1);
+ if (archive_wstring_ensure(&(a->_name_data),
+ 8 + wcslen(wn) + 1) == NULL) {
+ free(wn);
+ return (-1);
+ }
a->name = a->_name_data.s;
/* Prepend "\\?\UNC\" */
archive_wstrncpy(&(a->_name_data),
free(wsp);
return (-1);
}
- archive_wstring_ensure(&(a->_name_data),
- 4 + 2 + wcslen(wn) + 1);
+ if (archive_wstring_ensure(&(a->_name_data),
+ 4 + 2 + wcslen(wn) + 1) == NULL) {
+ free(wsp);
+ free(wn);
+ return (-1);
+ }
a->name = a->_name_data.s;
/* Prepend "\\?\" and drive name. */
archive_wstrncpy(&(a->_name_data), L"\\\\?\\", 4);
free(wsp);
return (-1);
}
- archive_wstring_ensure(&(a->_name_data), 4 + l + 1 + wcslen(wn) + 1);
+ if (archive_wstring_ensure(&(a->_name_data),
+ 4 + l + 1 + wcslen(wn) + 1) == NULL) {
+ free(wsp);
+ free(wn);
+ return (-1);
+ }
a->name = a->_name_data.s;
/* Prepend "\\?\" and drive name if not already added. */
if (l > 3 && wsp[0] == L'\\' && wsp[1] == L'\\' &&