summaryrefslogtreecommitdiffstats
path: root/common/mkdir_p.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2015-10-18 19:37:41 +0200
committerWerner Koch <wk@gnupg.org>2015-10-18 20:08:37 +0200
commite64c805b0c270d859ddf2c35d573110cf25e8d48 (patch)
tree35abc3875ed85b0afdfd8b0ce53b80775c9580b1 /common/mkdir_p.c
parentMove http module from common/ to dirmngr/. (diff)
downloadgnupg2-e64c805b0c270d859ddf2c35d573110cf25e8d48.tar.xz
gnupg2-e64c805b0c270d859ddf2c35d573110cf25e8d48.zip
common: Avoid warning about const char ** assignment.
* common/mkdir_p.c (gnupg_amkdir_p): Also strdup first item. Return an error on malloc failure. (gnupg_mkdir_p): Fix type of dirs and tmp_dirs. -- The code was correct but it inhibits type checking. Instead of casting it seems easier to simply allocate also the the first item in DIRS. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'common/mkdir_p.c')
-rw-r--r--common/mkdir_p.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/common/mkdir_p.c b/common/mkdir_p.c
index 43f9e024c..2e93d6592 100644
--- a/common/mkdir_p.c
+++ b/common/mkdir_p.c
@@ -53,16 +53,21 @@ gnupg_amkdir_p (const char **directory_components)
/* log_debug ("%s: %d directory components.\n", __func__, count); */
- dirs = xtrycalloc (count, sizeof (char *));
+ dirs = xtrycalloc (count, sizeof *dirs);
if (!dirs)
return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
for (i = 0; directory_components[i]; i ++)
{
if (i == 0)
- dirs[i] = directory_components[i];
+ dirs[i] = xtrystrdup (directory_components[i]);
else
- dirs[i] = make_filename (dirs[i - 1], directory_components[i], NULL);
+ dirs[i] = make_filename_try (dirs[i-1], directory_components[i], NULL);
+ if (!dirs[i])
+ {
+ err = gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
+ goto out;
+ }
/* log_debug ("%s: Directory %d: `%s'.\n", __func__, i, dirs[i]); */
}
@@ -127,7 +132,7 @@ gnupg_amkdir_p (const char **directory_components)
}
out:
- for (i = 1; i < count; i ++)
+ for (i = 0; i < count; i ++)
xfree (dirs[i]);
xfree (dirs);
@@ -144,7 +149,7 @@ gnupg_mkdir_p (const char *directory_component, ...)
gpg_error_t err = 0;
int i;
int space = 1;
- char **dirs;
+ const char **dirs;
dirs = xtrymalloc (space * sizeof (char *));
if (!dirs)
@@ -157,7 +162,7 @@ gnupg_mkdir_p (const char *directory_component, ...)
{
if (i == space)
{
- char **tmp_dirs;
+ const char **tmp_dirs;
space = 2 * space;
tmp_dirs = xtryrealloc (dirs, space * sizeof (char *));