Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Cores almost on demand in patcompile()



On Thu, 20 Oct 2016 07:55:13 +0200
Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
> Valgrind outputs two "Invalid read of size 8" messages. Don't know why
> there are no line pointers to source, however the reads are in
> patcompile(). I'm afraid that are PATNEXT invocations, final
> segmentation-fault places.

Thanks, I think we're getting somewhere.  Yes, I think the actual
problem is in the block where you've been adding the debugging.
It's the same one Bart noted when he managed to get this to show up with
the line numbers.

I think this:

			if (nmeta) {
			    char *oldpatout = patout;
			    patadd(NULL, 0, nmeta, 0);
			    /*
			     * Yuk.
			     */
			    p = (Patprog)patout;
			    opnd = patout + (opnd - oldpatout);
			    dst = patout + startoff;
			}

can have an effect on where pscan should be pointing because of the
reallocation.  A better way of doing this would be loop first to count
the space needed then allocate it.

See if this helps (I think next is the key one to update):

diff --git a/Src/pattern.c b/Src/pattern.c
index 4e2f236..158bfd5 100644
--- a/Src/pattern.c
+++ b/Src/pattern.c
@@ -669,12 +669,16 @@ patcompile(char *exp, int inflags, char **endexp)
 				nmeta++;
 			if (nmeta) {
 			    char *oldpatout = patout;
+			    ptrdiff_t pd;
 			    patadd(NULL, 0, nmeta, 0);
 			    /*
 			     * Yuk.
 			     */
 			    p = (Patprog)patout;
-			    opnd = patout + (opnd - oldpatout);
+			    pd = patout - oldpatout;
+			    opnd += pd;
+			    pscan += pd;
+			    next += pd;
 			    dst = patout + startoff;
 			}
 


pws



Messages sorted by: Reverse Date, Date, Thread, Author