aboutsummaryrefslogtreecommitdiffstats
path: root/utils.h
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2015-02-27 19:37:24 +0100
committerDavid Sterba <dsterba@suse.cz>2015-06-11 01:10:10 +0200
commit6d7999d5b747283314c0f3833a3d9515f674a446 (patch)
tree5af8bb4c6219e6264f7b5ecb680d7b475c9a613f /utils.h
parent4ceffd0927360c83bec94606112b4e59cb7d2d73 (diff)
downloadbtrfs-progs-6d7999d5b747283314c0f3833a3d9515f674a446.tar.gz
btrfs-progs-6d7999d5b747283314c0f3833a3d9515f674a446.tar.xz
btrfs-progs-6d7999d5b747283314c0f3833a3d9515f674a446.zip
btrfs-progs: use less memory for pretty_size_mode buffers
Anand reports that the static buffers used for pertty size strings cause a stack overflow on SPARC. Zach proposed to change the printf format to wrap the number and the suffix into a macro. This would require to change all callsites of pretty_size* and is not very convienient to write. This patch replaces the per-call-site static buffers with a limited number for slots that would be used on each invokation of pretty_size and wrap around. The number of array slots shall be 10 for now, in current codebase there are no more than 2 calls to pretty_size in a single argument list. Reported-by: Anand Jain <Anand.Jain@oracle.com> CC: Zach Brown <zab@zabbo.net> Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'utils.h')
-rw-r--r--utils.h7
1 files changed, 1 insertions, 6 deletions
diff --git a/utils.h b/utils.h
index 9b6a07b..7260035 100644
--- a/utils.h
+++ b/utils.h
@@ -129,12 +129,7 @@ int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
int pretty_size_snprintf(u64 size, char *str, size_t str_bytes, unsigned unit_mode);
#define pretty_size(size) pretty_size_mode(size, UNITS_DEFAULT)
-#define pretty_size_mode(size, mode) \
- ({ \
- static __thread char _str[32]; \
- (void)pretty_size_snprintf((size), _str, sizeof(_str), (mode)); \
- _str; \
- })
+const char *pretty_size_mode(u64 size, unsigned mode);
int get_mountpt(char *dev, char *mntpt, size_t size);
u64 parse_size(char *s);