bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] gawk-5.0.0: use-of-uninitialized-value


From: Andrew J. Schorr
Subject: Re: [bug-gawk] gawk-5.0.0: use-of-uninitialized-value
Date: Fri, 21 Jun 2019 08:54:46 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

On Fri, Jun 21, 2019 at 02:49:51AM -0600, address@hidden wrote:
> diff --git a/awkgram.y b/awkgram.y
> index 3cbcfd31..a940ac9d 100644
> --- a/awkgram.y
> +++ b/awkgram.y
> @@ -3185,6 +3185,7 @@ get_src_buf()
>               sourcefile->bufsize = l;
>               newfile = true;
>               emalloc(sourcefile->buf, char *, sourcefile->bufsize, 
> "get_src_buf");
> +             memset(sourcefile->buf, '\0', sourcefile->bufsize);     // keep 
> valgrind happy
>               lexptr = lexptr_begin = lexeme = sourcefile->buf;
>               savelen = 0;
>               sourceline = 1;
> 

Thanks for chasing this down. I have two questions:

1. Mightn't it be more efficient to use ezalloc instead of emalloc+memset?

2. I had noticed that the valgrind complaint occurred only when the
program file contained 'A', but not when it contained 'A\n'. There was
also no complaint when 'A' was supplied on the command line. But I didn't
debug further. Why did the absence of a newline at the end of a file
make a difference, or the fact that it was in a file instead of on the
command line? It seems a bit odd. I wonder if zapping the memory is just
covering up a subtle problem...

bash-4.2$ hexdump -vC /tmp/A.awk 
00000000  41                                                |A|
00000001
bash-4.2$ echo 1 | valgrind ./gawk -f /tmp/A.awk
==4176== Memcheck, a memory error detector
==4176== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==4176== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==4176== Command: ./gawk -f /tmp/A.awk
==4176== 
==4176== Conditional jump or move depends on uninitialised value(s)
==4176==    at 0x41539E: yylex (awkgram.y:4477)
==4176==    by 0x41539E: yyparse (awkgram.c:1836)
==4176==    by 0x417E03: parse_program (awkgram.y:2776)
==4176==    by 0x407A6F: main (main.c:473)
==4176== 
==4176== 
==4176== HEAP SUMMARY:
==4176==     in use at exit: 100,080 bytes in 455 blocks
==4176==   total heap usage: 506 allocs, 51 frees, 127,731 bytes allocated
==4176== 
==4176== LEAK SUMMARY:
==4176==    definitely lost: 0 bytes in 0 blocks
==4176==    indirectly lost: 0 bytes in 0 blocks
==4176==      possibly lost: 0 bytes in 0 blocks
==4176==    still reachable: 100,080 bytes in 455 blocks
==4176==         suppressed: 0 bytes in 0 blocks
==4176== Rerun with --leak-check=full to see details of leaked memory
==4176== 
==4176== For counts of detected and suppressed errors, rerun with: -v
==4176== Use --track-origins=yes to see where uninitialised values come from
==4176== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

bash-4.2$ hexdump -vC /tmp/B.awk 
00000000  41 0a                                             |A.|
00000002
bash-4.2$ echo 1 | valgrind ./gawk -f /tmp/B.awk
==4204== Memcheck, a memory error detector
==4204== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==4204== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==4204== Command: ./gawk -f /tmp/B.awk
==4204== 
==4204== 
==4204== HEAP SUMMARY:
==4204==     in use at exit: 100,080 bytes in 455 blocks
==4204==   total heap usage: 506 allocs, 51 frees, 127,731 bytes allocated
==4204== 
==4204== LEAK SUMMARY:
==4204==    definitely lost: 0 bytes in 0 blocks
==4204==    indirectly lost: 0 bytes in 0 blocks
==4204==      possibly lost: 0 bytes in 0 blocks
==4204==    still reachable: 100,080 bytes in 455 blocks
==4204==         suppressed: 0 bytes in 0 blocks
==4204== Rerun with --leak-check=full to see details of leaked memory
==4204== 
==4204== For counts of detected and suppressed errors, rerun with: -v
==4204== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

bash-4.2$ echo 1 | valgrind ./gawk 'A'
==4217== Memcheck, a memory error detector
==4217== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==4217== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==4217== Command: ./gawk A
==4217== 
==4217== 
==4217== HEAP SUMMARY:
==4217==     in use at exit: 100,028 bytes in 452 blocks
==4217==   total heap usage: 503 allocs, 51 frees, 127,553 bytes allocated
==4217== 
==4217== LEAK SUMMARY:
==4217==    definitely lost: 0 bytes in 0 blocks
==4217==    indirectly lost: 0 bytes in 0 blocks
==4217==      possibly lost: 0 bytes in 0 blocks
==4217==    still reachable: 100,028 bytes in 452 blocks
==4217==         suppressed: 0 bytes in 0 blocks
==4217== Rerun with --leak-check=full to see details of leaked memory
==4217== 
==4217== For counts of detected and suppressed errors, rerun with: -v
==4217== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Regards,
Andy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]