diff options
author | Jin Qian <jinqian@google.com> | 2017-01-06 16:30:34 -0800 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2017-05-23 22:58:04 -0400 |
commit | a5d3c5ba686cfeb21d1d679f7ca2dc8f09748b75 (patch) | |
tree | bedd5ab8621ee362f0af4b56d8fb5f1a46278100 /lib | |
parent | ca2e5d42a22df8fa1e86c96c4a13e923a7efe9d3 (diff) | |
download | e2fsprogs-a5d3c5ba686cfeb21d1d679f7ca2dc8f09748b75.tar.gz |
AOSP: libext2fs: fix sparse param parsing on mac build
Flag m is not supported on macos sscanf. Fall back to manually
allocate the string.
Use strict format to skip ":" between params.
Change-Id: Ic4f3747708423d0504ea40fb5cb116068f4a7ab8
From AOSP commit: 901472babf4ea5e4d2d44aa16834b1c899c8937f
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ext2fs/sparse_io.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/ext2fs/sparse_io.c b/lib/ext2fs/sparse_io.c index b6168cb7b..a307859f8 100644 --- a/lib/ext2fs/sparse_io.c +++ b/lib/ext2fs/sparse_io.c @@ -196,16 +196,21 @@ static errcode_t read_sparse_argv(const char *name, bool is_fd, { int ret; sparse_params->fd = -1; - sparse_params->file = NULL; sparse_params->block_size = 0; sparse_params->blocks_count = 0; + sparse_params->file = malloc(strlen(name) + 1); + if (!sparse_params->file) { + fprintf(stderr, "failed to alloc %zu\n", strlen(name) + 1); + return EXT2_ET_NO_MEMORY; + } + if (is_fd) { ret = sscanf(name, "%d:%llu:%u", &sparse_params->fd, (unsigned long long *)&sparse_params->blocks_count, &sparse_params->block_size); } else { - ret = sscanf(name, "%m[^:]:%llu%*[:]%u", &sparse_params->file, + ret = sscanf(name, "%[^:]%*[:]%llu%*[:]%u", sparse_params->file, (unsigned long long *)&sparse_params->blocks_count, &sparse_params->block_size); } |