D: Convert/parse uint integer to string. (@nogc)

Dom DiSc dominikus at scherkl.de
Tue Nov 28 09:43:47 UTC 2023


On Tuesday, 28 November 2023 at 08:51:21 UTC, Mark Davies wrote:
> On Friday, 24 November 2023 at 09:35:00 UTC, BoQsc wrote:
> ```
> import std.stdio;
>
> char[10] longToString(long n) @nogc
> ```

For a 'long' 10 characters is likely to be not enough (long max 
is 9223372036854775808 which has 19 chars, and you should reserve 
additional one for the sign and one for the terminating null), so 
I would at least recommend using char[21].

with char[10] your function becomes a big hole in your security, 
as it can easily be misused to write 10 bytes of freely 
selectable garbage behind your allocated memory.

But as you want to avoid the gc, security might not be a goal for 
you, so continue living in the 1970's.


More information about the Digitalmars-d-learn mailing list