Commit db9439cdc7b684f2f1d0f1a4ca0a33a6c114d9ea

Authored by perry.werneck@gmail.com
1 parent 75e79e39

Corrigindo erro no gerenciamento de memoria

Showing 1 changed file with 8 additions and 3 deletions   Show diff stats
selection.c
... ... @@ -428,24 +428,29 @@ LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len)
428 428 buffer = malloc(len+1);
429 429 ptr = buffer;
430 430  
431   - while(len-- > 0)
  431 + trace("len=%d buffer=%p",len,buffer);
  432 +
  433 + while(len > 0)
432 434 {
433 435 if(h->text[offset].attr & LIB3270_ATTR_CG)
434 436 *ptr = ' ';
435 437 else if(h->text[offset].chr)
436 438 *ptr = h->text[offset].chr;
437 439 else
438   - *ptr = " ";
  440 + *ptr = ' ';
439 441  
440 442 ptr++;
441 443 offset++;
  444 + len--;
442 445  
443   - if((offset%h->cols) == 0)
  446 + if((offset%h->cols) == 0 && len > 0)
444 447 {
445 448 *(ptr++) = '\n';
446 449 len--;
447 450 }
448 451 }
  452 + trace("len=%d buffer=%p pos=%d",len,buffer,ptr-buffer);
  453 +
449 454 *ptr = 0;
450 455  
451 456 return buffer;
... ...