From: Michihiro NAKAJIMA Date: Mon, 26 Dec 2011 02:38:42 +0000 (-0500) Subject: Issue 203. Fix build failure without PATH_MAX. X-Git-Tag: v3.0.3~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f2b5cf949e128c30391d2b410206804eb107eae;p=thirdparty%2Flibarchive.git Issue 203. Fix build failure without PATH_MAX. Merge r4004 and r4005 from trunk. SVN-Revision: 4006 --- diff --git a/libarchive/archive_write_set_format_xar.c b/libarchive/archive_write_set_format_xar.c index 4447f5a8f..bb9b55184 100644 --- a/libarchive/archive_write_set_format_xar.c +++ b/libarchive/archive_write_set_format_xar.c @@ -684,21 +684,24 @@ xar_write_data(struct archive_write *a, const void *buff, size_t s) archive_string_empty(&(xar->cur_file->script)); if (rsize > 2 && b[0] == '#' && b[1] == '!') { - char path[PATH_MAX]; size_t i, end, off; - end = sizeof(path); - if (end > rsize) - end = rsize; off = 2; if (b[off] == ' ') off++; +#ifdef PATH_MAX + if ((rsize - off) > PATH_MAX) + end = off + PATH_MAX; + else +#endif + end = rsize; + /* Find the end of a script path. */ for (i = off; i < end && b[i] != '\0' && b[i] != '\n' && b[i] != '\r' && b[i] != ' ' && b[i] != '\t'; i++) - path[i - off] = b[i]; - path[i - off] = '\0'; - archive_strcpy(&(xar->cur_file->script), path); + ; + archive_strncpy(&(xar->cur_file->script), b + off, + i - off); } } #endif diff --git a/libarchive/test/test_sparse_basic.c b/libarchive/test/test_sparse_basic.c index e8c2f3385..0656f2ff7 100644 --- a/libarchive/test/test_sparse_basic.c +++ b/libarchive/test/test_sparse_basic.c @@ -360,7 +360,7 @@ test_sparse_whole_file_data() DEFINE_TEST(test_sparse_basic) { - char cwd[PATH_MAX+1]; + char *cwd; struct archive *a; /* * The alignment of the hole of sparse files deeply depends @@ -420,9 +420,15 @@ DEFINE_TEST(test_sparse_basic) /* Check if the filesystem where CWD on can * report the number of the holes of a sparse file. */ - if (!assert(getcwd(cwd, sizeof(cwd)-1) != NULL)) +#ifdef PATH_MAX + cwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */ +#else + cwd = getcwd(NULL, 0); +#endif + if (!assert(cwd != NULL)) return; if (!is_sparse_supported(cwd)) { + free(cwd); skipping("This filesystem or platform do not support " "the reporting of the holes of a sparse file through " "API such as lseek(HOLE)"); @@ -450,4 +456,5 @@ DEFINE_TEST(test_sparse_basic) verify_sparse_file2(a, "file0", sparse_file0, 5, 1); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); + free(cwd); }