helpextract.c: removed some static buffer
PATCH 2/7 helpextract.c: removed some static buffer
Removed some static buffer, and replaced by a dynamic memory allocation in order to support bigger text.
Comments are welcome.
BR
G.Baroncelli
Signed-off-by Goffredo Baroncelli <[email protected]>
--- helpextract.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-)
helpextract.c +7 -4
@@ -9,7 +9,7 @@#define PREFIX_END " ****"#define PREFIX_SKIP " * " -#define LINEBUF 1024 +#define LINEBUF 4024char **msgs=0 ;int nmsg=0 ;
@@ -188,7 +188,9 @@ static int search_in_file(char *nf){/* remove all the escape sequence except \\ */ static char *my_escape (char *src,char *filters[] ){ -static char buffer[LINEBUF *5 ]; +char *buffer=NULL ; + + buffer =xrealloc (buffer,strlen (src)*2 +1 );int i=0 ;while (*src){
@@ -387,14 +389,15 @@ static void dump_man_page(){ fmt =find_section ("man btrfs command format" );for (i =0 ; i < nmsg && fmt>=0 ; i++ ){ -char big2[LINEBUF *5 ]; +char *big2;if (strncmp ("btrfs " ,msgs[i*4 ],6 ) || !strcmp ("btrfs introduction" , msgs[i*4 ] ) || !strcmp ("btrfs notes" , msgs[i*4 ] ) )continue ; -strcpy (big2,escape_man_page (msgs[i*4 +3 ])); + big2 =xstrdup (escape_man_page (msgs[i*4 +3 ]));printf (msgs[fmt*4 +3 ],escape_man_page (msgs[i*4 +1 ]), big2); +free (big2); }
Signature · 2 lines
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <[email protected]> Key fingerprint = 4769 7E51 5293 D36C 814E C054 BF04 F161 3DC5 0512
helpextract.c +7 -4
@@ -9,7 +9,7 @@#define PREFIX_END " ****"#define PREFIX_SKIP " * " -#define LINEBUF 1024 +#define LINEBUF 4024char **msgs=0 ;int nmsg=0 ;
@@ -188,7 +188,9 @@ static int search_in_file(char *nf){/* remove all the escape sequence except \\ */ static char *my_escape (char *src,char *filters[] ){ -static char buffer[LINEBUF *5 ]; +char *buffer=NULL ; + + buffer =xrealloc (buffer,strlen (src)*2 +1 );int i=0 ;while (*src){
@@ -387,14 +389,15 @@ static void dump_man_page(){ fmt =find_section ("man btrfs command format" );for (i =0 ; i < nmsg && fmt>=0 ; i++ ){ -char big2[LINEBUF *5 ]; +char *big2;if (strncmp ("btrfs " ,msgs[i*4 ],6 ) || !strcmp ("btrfs introduction" , msgs[i*4 ] ) || !strcmp ("btrfs notes" , msgs[i*4 ] ) )continue ; -strcpy (big2,escape_man_page (msgs[i*4 +3 ])); + big2 =xstrdup (escape_man_page (msgs[i*4 +3 ]));printf (msgs[fmt*4 +3 ],escape_man_page (msgs[i*4 +1 ]), big2); +free (big2); }