Commit db9439cdc7b684f2f1d0f1a4ca0a33a6c114d9ea
1 parent
75e79e39
Exists in
master
and in
3 other branches
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,24 +428,29 @@ LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len) | ||
| 428 | buffer = malloc(len+1); | 428 | buffer = malloc(len+1); |
| 429 | ptr = buffer; | 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 | if(h->text[offset].attr & LIB3270_ATTR_CG) | 435 | if(h->text[offset].attr & LIB3270_ATTR_CG) |
| 434 | *ptr = ' '; | 436 | *ptr = ' '; |
| 435 | else if(h->text[offset].chr) | 437 | else if(h->text[offset].chr) |
| 436 | *ptr = h->text[offset].chr; | 438 | *ptr = h->text[offset].chr; |
| 437 | else | 439 | else |
| 438 | - *ptr = " "; | 440 | + *ptr = ' '; |
| 439 | 441 | ||
| 440 | ptr++; | 442 | ptr++; |
| 441 | offset++; | 443 | offset++; |
| 444 | + len--; | ||
| 442 | 445 | ||
| 443 | - if((offset%h->cols) == 0) | 446 | + if((offset%h->cols) == 0 && len > 0) |
| 444 | { | 447 | { |
| 445 | *(ptr++) = '\n'; | 448 | *(ptr++) = '\n'; |
| 446 | len--; | 449 | len--; |
| 447 | } | 450 | } |
| 448 | } | 451 | } |
| 452 | + trace("len=%d buffer=%p pos=%d",len,buffer,ptr-buffer); | ||
| 453 | + | ||
| 449 | *ptr = 0; | 454 | *ptr = 0; |
| 450 | 455 | ||
| 451 | return buffer; | 456 | return buffer; |