Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [BTRFS-PROG][PATCH 2/7] helpextract.c: removed some static buffer
@ 2011-11-02 21:23 Goffredo Baroncelli
  0 siblings, 0 replies; only message in thread
From: Goffredo Baroncelli @ 2011-11-02 21:23 UTC (permalink / raw)
  To: linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 1523 bytes --]

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 <kreijack@inwind.it>

---
 helpextract.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/helpextract.c b/helpextract.c
index a729074..e708b9e 100644
--- a/helpextract.c
+++ b/helpextract.c
@@ -9,7 +9,7 @@
 #define PREFIX_END 	" ****"
 #define PREFIX_SKIP	" * "
 
-#define LINEBUF		1024
+#define LINEBUF		4024
 
 char **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);
 
 	}
 

-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack@inwind.it>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512

[-- Attachment #1.2: send-via-kmail-attach-3522-1320267550-26913.msg --]
[-- Type: text/x-patch, Size: 1081 bytes --]

diff --git a/helpextract.c b/helpextract.c
index a729074..e708b9e 100644
--- a/helpextract.c
+++ b/helpextract.c
@@ -9,7 +9,7 @@
 #define PREFIX_END 	" ****"
 #define PREFIX_SKIP	" * "
 
-#define LINEBUF		1024
+#define LINEBUF		4024
 
 char **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);
 
 	}
 


[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-11-02 21:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-02 21:23 [BTRFS-PROG][PATCH 2/7] helpextract.c: removed some static buffer Goffredo Baroncelli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox