Commit 3504b0162e4d43ec56937c809c4107bb36fba171

Authored by perry.werneck@gmail.com
1 parent 7162468b

Corrigindo segfault em windows

src/gtk/dialog.c
@@ -387,10 +387,13 @@ @@ -387,10 +387,13 @@
387 { 387 {
388 gchar *text = v3270_get_text(widget); 388 gchar *text = v3270_get_text(widget);
389 389
390 - trace("Action %s activated on widget %p",gtk_action_get_name(action),widget); 390 + trace("Action %s activated on widget %p text=%p",gtk_action_get_name(action),widget,text);
391 391
392 if(!text) 392 if(!text)
  393 + {
  394 + g_warning("%s","Buffer contents was NULL");
393 return; 395 return;
  396 + }
394 397
395 save_dialog( action, 398 save_dialog( action,
396 widget, 399 widget,
src/gtk/main.c
@@ -102,13 +102,14 @@ static int initialize(void) @@ -102,13 +102,14 @@ static int initialize(void)
102 return EINVAL; 102 return EINVAL;
103 } 103 }
104 104
  105 + return 0;
105 } 106 }
106 107
107 int main (int argc, char *argv[]) 108 int main (int argc, char *argv[])
108 { 109 {
109 gtk_init(&argc, &argv); 110 gtk_init(&argc, &argv);
110 111
111 - if(!initialize()) 112 + if(initialize())
112 return -1; 113 return -1;
113 114
114 configuration_init(); 115 configuration_init();
src/gtk/print.c
@@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
31 31
32 #include "globals.h" 32 #include "globals.h"
33 #include "v3270/v3270.h" 33 #include "v3270/v3270.h"
  34 + #include <lib3270/selection.h>
34 35
35 /*--[ Structs ]--------------------------------------------------------------------------------------*/ 36 /*--[ Structs ]--------------------------------------------------------------------------------------*/
36 37
src/lib3270/selection.c
@@ -317,12 +317,13 @@ static char * get_text(H3270 *hSession,unsigned char all) @@ -317,12 +317,13 @@ static char * get_text(H3270 *hSession,unsigned char all)
317 { 317 {
318 int row, col, baddr; 318 int row, col, baddr;
319 char *ret; 319 char *ret;
320 - size_t sz = 0; 320 + size_t buflen = (hSession->rows * (hSession->cols+1))+1;
  321 + size_t sz = 0;
321 322
322 if(!lib3270_connected(hSession)) 323 if(!lib3270_connected(hSession))
323 return NULL; 324 return NULL;
324 325
325 - ret = malloc(hSession->rows * (hSession->cols+1)); 326 + ret = malloc(buflen);
326 327
327 baddr = 0; 328 baddr = 0;
328 for(row=0;row < hSession->rows;row++) 329 for(row=0;row < hSession->rows;row++)
@@ -342,9 +343,19 @@ static char * get_text(H3270 *hSession,unsigned char all) @@ -342,9 +343,19 @@ static char * get_text(H3270 *hSession,unsigned char all)
342 if(cr) 343 if(cr)
343 ret[sz++] = '\n'; 344 ret[sz++] = '\n';
344 } 345 }
345 - ret[sz] = 0;  
346 346
347 - return realloc(ret,sz+1); 347 + if(!sz)
  348 + {
  349 + free(ret);
  350 + return NULL;
  351 + }
  352 +
  353 + ret[sz++] = 0;
  354 +
  355 + if(sz != buflen)
  356 + ret = realloc(ret,sz);
  357 +
  358 + return ret;
348 } 359 }
349 360
350 LIB3270_EXPORT char * lib3270_get_text(H3270 *hSession) 361 LIB3270_EXPORT char * lib3270_get_text(H3270 *hSession)