[hipl-dev] Re: [Merge] lp:~hipl-core/hipl/libhip into lp:hipl

  • From: Xin Gu <eric.nevup@xxxxxxxxx>
  • To: hipl-dev@xxxxxxxxxxxxx
  • Date: Tue, 21 Feb 2012 17:36:57 +0200

Hi,

On 20/02/12 22:03, Christof Mroz wrote:
Review: Needs Fixing

=== modified file 'lib/core/hostid.c'
--- lib/core/hostid.c   2011-11-10 10:35:47 +0000
+++ lib/core/hostid.c   2012-02-20 08:33:22 +0000
@@ -743,11 +744,17 @@
                  goto out_err;
              }
          } else if (!use_default) {
+            char hi_file_dup[strlen(hi_file) + 1];
+            strcpy(hi_file_dup, hi_file);
+            if ((err = check_and_create_dir(dirname(hi_file_dup), 
HIP_DIR_MODE))) {
+                HIP_ERROR("Could not create direcory for path: %s\n", hi_file);
+                goto out_err;
+            }
I investigated a bit and seems like PATH_MAX is 4096 chars on linux, which is 
probably OK even for stacks on embedded devices, but strdup() would be safer 
nevertheless.
My apologies for advising you to use the stack for that in the last mail (see 
also further below).

Probably unrelated: should this handle recursive mkdir()? 
check_and_create_dir() currently does not, as far as I see.

Related stack memory usages have been reverted to malloc.

Regarding to check_and_create_dir(), in libhipl, using it is save, because the parent directory (user's home folder) should exist.

Nice hints for linkedlist, it greatly shorten the lines of code :)


Xin

Other related posts: