# HG changeset patch # User mhessling@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1159677602 0 # Node ID e49524bc2f076f6dbdd7a460a2214e4f2bff2881 # Parent b4cb30f47a97372abdd9a5ec76ba516d5ca63c54 Fix trailing junk on dw_mle_export() diff -r b4cb30f47a97 -r e49524bc2f07 gtk/dw.c --- a/gtk/dw.c Thu Sep 28 01:42:32 2006 +0000 +++ b/gtk/dw.c Sun Oct 01 04:40:02 2006 +0000 @@ -4211,7 +4211,7 @@ * Grabs text from an MLE box. * Parameters: * handle: Handle to the MLE to be queried. - * buffer: Text buffer to be exported. + * buffer: Text buffer to be exported. MUST allow for trailing nul character. * startpoint: Point to start grabbing text. * length: Amount of text to be grabbed. */ @@ -4223,7 +4223,7 @@ DW_MUTEX_LOCK; /* force the return value to nul in case the following tests fail */ if(buffer) - strcpy(buffer,""); + buffer[0] = '\0'; #if GTK_MAJOR_VERSION > 1 if(GTK_IS_SCROLLED_WINDOW(handle)) #else @@ -4245,17 +4245,25 @@ if(text) /* Should this get freed? */ { if(buffer) - strcpy(buffer, text); + memcpy(buffer, text); } } #else if(tmp && GTK_IS_TEXT(tmp)) { - text = gtk_editable_get_chars(GTK_EDITABLE(&(GTK_TEXT(tmp)->editable)), startpoint, startpoint + length - 1); + text = gtk_editable_get_chars(GTK_EDITABLE(&(GTK_TEXT(tmp)->editable)), 0, -1); /* get the complete contents */ if(text) { if(buffer) - strcpy(buffer, text); + { + len = strlen(text); + if(startpoint < len) + { + max = min(length, len - startpoint); + memcpy(buffer, &text[startpoint], max); + buffer[max] = '\0'; + } + } g_free(text); } } diff -r b4cb30f47a97 -r e49524bc2f07 win/dw.c --- a/win/dw.c Thu Sep 28 01:42:32 2006 +0000 +++ b/win/dw.c Sun Oct 01 04:40:02 2006 +0000 @@ -5886,7 +5886,7 @@ * Grabs text from an MLE box. * Parameters: * handle: Handle to the MLE to be queried. - * buffer: Text buffer to be exported. + * buffer: Text buffer to be exported. MUST allow for trailing nul character. * startpoint: Point to start grabbing text. * length: Amount of text to be grabbed. */ @@ -5905,6 +5905,7 @@ max = MIN(length, len - startpoint); memcpy(buffer, &tmpbuf[startpoint], max); + buffer[max] = '\0'; } free(tmpbuf);