From 06998b4cbfaae9cbd4df990f19c1351c653c40ea Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 23 Jan 2014 20:32:15 +0300 Subject: [PATCH] string_len: export get_formatted_string_size() You pass this a function call and a parameter number like this: snprintf(buf, sizeof(buf), "%d %d %d\n", a, b, c); The call is snprintf and the parameter with the string is 2. It tells you the max length of the string (including the NUL char, unfortunately. Maybe that should change in the future). Signed-off-by: Dan Carpenter --- check_string_len.c | 4 ++-- smatch.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/check_string_len.c b/check_string_len.c index 37467a42..48166f37 100644 --- a/check_string_len.c +++ b/check_string_len.c @@ -160,7 +160,7 @@ out_no_arg: return ret; } -static int get_string_size(struct expression *call, int arg) +int get_formatted_string_size(struct expression *call, int arg) { struct expression *expr; char *p; @@ -202,7 +202,7 @@ static void match_not_limited(const char *fn, struct expression *call, void *inf if (buf_size <= 0) return; - size = get_string_size(call, params->string); + size = get_formatted_string_size(call, params->string); if (size <= 0) return; if (size <= buf_size) diff --git a/smatch.h b/smatch.h index 4b49e474..717612ac 100644 --- a/smatch.h +++ b/smatch.h @@ -722,4 +722,7 @@ int has_symbol(struct expression *expr, struct symbol *sym); int has_variable(struct expression *expr, struct expression *var); int has_inc_dec(struct expression *expr); +/* check_string_len.c */ +int get_formatted_string_size(struct expression *call, int arg); + #endif /* !SMATCH_H_ */ -- 2.11.4.GIT