[Issue 12980] Undefined behavior: Assignment of static string to dynamic string

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jun 24 04:15:40 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=12980

bearophile_hugs at eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs at eml.cc

--- Comment #1 from bearophile_hugs at eml.cc ---
(In reply to Yuriy from comment #0)

> char[10] getSomeString()
> {
> 	char[10] result;
> 	int i = 0;
> 	for (char a = '0'; a <= '9'; ++a)
> 	{
> 		result[i++] = a;
> 	}
> 	return result;
> }

D is not fully memory-safe. A starting point to avoid such troubles is to
require a [] at that return point:

    }
    return result[];
}

--


More information about the Digitalmars-d-bugs mailing list