www.digitalmars.com         C & C++   DMDScript  

D.gnu - Missing NUL terminator when using "-MT <file>" option

reply Sebastien Alaiwan <sebastien.alaiwan+contact gmail.com> writes:
Hi,

It seems that the output target name gets corrupted (see the extra chars at the
end of 'MyTargetName'):

    *$ cat test.d*
    // empty file

    *$ gdc -Isrc -MM "test.d" -MT "MyTargetName" -MF "test.deps"*

    *$ cat test.deps*
    MyTargetName�: test.d

    *$ gdc --version*
    gdc (Debian 11.2.0-10) 11.2.0
    Copyright (C) 2021 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    *$*


Here's the fix I'm suggesting:

    diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
    index be6330fbd..4749bfb98 100644
    --- a/gcc/d/d-lang.cc
    +++ b/gcc/d/d-lang.cc
       -110,6 +110,7    deps_add_target (const char *target, bool quoted)
        if (!quoted)
          {
            obstack_grow0 (&buffer, target, strlen (target));
    +      obstack_1grow (&buffer, '\0');
            d_option.deps_target.safe_push ((const char *) obstack_finish
(&buffer));
            return;
          }


Cheers,

Sebastien Alaiwan
Nov 28 2021
parent reply Iain Buclaw <ibuclaw gdcproject.org> writes:
On Sunday, 28 November 2021 at 13:58:49 UTC, Sebastien Alaiwan 
wrote:
 Hi,

 It seems that the output target name gets corrupted (see the 
 extra chars at the end of 'MyTargetName'):

     *$ cat test.d*
     // empty file

     *$ gdc -Isrc -MM "test.d" -MT "MyTargetName" -MF 
 "test.deps"*

     *$ cat test.deps*
     MyTargetName�: test.d

     *$ gdc --version*
     gdc (Debian 11.2.0-10) 11.2.0
     Copyright (C) 2021 Free Software Foundation, Inc.
     This is free software; see the source for copying 
 conditions.  There is NO
     warranty; not even for MERCHANTABILITY or FITNESS FOR A 
 PARTICULAR PURPOSE.

     *$*


 Here's the fix I'm suggesting:

     diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
     index be6330fbd..4749bfb98 100644
     --- a/gcc/d/d-lang.cc
     +++ b/gcc/d/d-lang.cc
        -110,6 +110,7    deps_add_target (const char *target, 
 bool quoted)
         if (!quoted)
           {
             obstack_grow0 (&buffer, target, strlen (target));
     +      obstack_1grow (&buffer, '\0');
             d_option.deps_target.safe_push ((const char *) 
 obstack_finish (&buffer));
             return;
           }
Hi Sebastien, That doesn't look right, obstack_grow0() already adds a null terminator. Did you test building current mainline to see if the issue still occurs? In all likelihood I just need to backport this patch which got applied back in July. https://gcc.gnu.org/pipermail/gcc-patches/2021-July/576395.html Which coincidentally, I was just asked to backport it to gcc-11 just the other day too. https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585450.html Iain.
Nov 28 2021
parent reply Sebastien Alaiwan <sebastien.alaiwan+contact gmail.com> writes:
On 28/11/2021 23.21, Iain Buclaw via D.gnu wrote:
 In all likelihood I just need to backport this patch which got applied back in
July.

 https://gcc.gnu.org/pipermail/gcc-patches/2021-July/576395.html

 Which coincidentally, I was just asked to backport it to gcc-11 just the other
day too.

 https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585450.html

 Iain.
Hi Iain, Indeed, you're right. Thanks for sorting this out (and thanks for your work on GDC !) Cheers, Sebastien
Nov 30 2021
parent Carlton Flores <saltbayfive protonmail.com> writes:
On Wednesday, 1 December 2021 at 07:31:38 UTC, Sebastien Alaiwan 
wrote:
 On 28/11/2021 23.21, Iain Buclaw via D.gnu wrote: 
 https://get-vidmate.com/vidmate-2014/  https://instasave.onl/
 In all likelihood I just need to backport this patch which got 
 applied back in July.

 https://gcc.gnu.org/pipermail/gcc-patches/2021-July/576395.html

 Which coincidentally, I was just asked to backport it to 
 gcc-11 just the other day too.

 https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585450.html

 Iain.
Hi Iain, Indeed, you're right. Thanks for sorting this out (and thanks for your work on GDC !) Cheers, Sebastien
Thanks for share !
Dec 21 2021