Petar Kirov [ZombineDev] wrote:

Please note that not all static immutable strings have to be null terminated. It is possible to generate a string at ctfe which may appear the same as string literal, but does not have the \0 at the end.

But in that case, the check `s.ptr[s.length] == 0` in fastStringZ
would do the trick, right?

with the edge case when something like the code i posted below managed to make `a` perfectly aligned with r/o area, and you got segfault by accising out-of-bounds byte.

BTW, are you sure? AFAIU, it doesn't matter if the CTFE engine returns a
non-null-terminated string expression, since the backend or the glue layer
would write it to the object file as if it was a null-terminated string.

        immutable ubyte[2] a = [65,66];
        enum string s = cast(string)a;
        immutable ubyte[2] b = [67,68]; // just to show you that there is no 
zero
        
        void main () {
          assert(s[$-1] == 0);
        }

Reply via email to