Skip to content

Commit 160a6f9

Browse files
authored
Merge pull request #23007 from WalterBright/machobj_unsstr
remove unsstr()
2 parents 87a06cb + 6bf1c3d commit 160a6f9

2 files changed

Lines changed: 8 additions & 24 deletions

File tree

compiler/src/dmd/backend/machobj.d

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,14 +2181,6 @@ void MachObj_alias(const(char)* n1,const(char)* n2)
21812181
assert(0);
21822182
}
21832183

2184-
@trusted
2185-
private char* unsstr (uint value)
2186-
{
2187-
__gshared char[64] buffer = void;
2188-
2189-
snprintf (buffer.ptr, buffer.length, "%d", value);
2190-
return buffer.ptr;
2191-
}
21922184

21932185
/*******************************
21942186
* Mangle a name.
@@ -2225,15 +2217,15 @@ char* obj_mangle2(Symbol* s,char* dest)
22252217
bool cond = (tyfunc(s.ty()) && !variadic(s.Stype));
22262218
if (cond)
22272219
{
2228-
char* pstr = unsstr(type_paramsize(s.Stype));
2229-
size_t pstrlen = strlen(pstr);
2230-
size_t destlen = len + 1 + pstrlen + 1;
2231-
2220+
char[64] buffer = void;
2221+
int n = snprintf(buffer.ptr, buffer.length, "%u", type_paramsize(s.Stype));
2222+
assert(n < buffer.length);
2223+
size_t destlen = len + 1 + n + 1; // n does not include terminating 0
22322224
if (destlen > DEST_LEN)
22332225
dest = cast(char*)mem_malloc(destlen);
22342226
memcpy(dest,name,len);
22352227
dest[len] = '@';
2236-
memcpy(dest + 1 + len, pstr, pstrlen + 1);
2228+
memcpy(dest + len + 1, buffer.ptr, n + 1);
22372229
break;
22382230
}
22392231
goto case;

compiler/src/dmd/backend/mscoffobj.d

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ enum DEST_LEN = (IDMAX + IDOHD + 1);
7373

7474
__gshared private
7575
{
76-
OutBuffer* fobjbuf; // contents of object file
76+
OutBuffer* fobjbuf; // contents of object file
7777

78-
OutBuffer* string_table; // string table for all other names
78+
OutBuffer* string_table; // string table for all other names
7979
public OutBuffer *ScnhdrBuf; // buffer to put section headers in
8080

8181
int scnhdr_cnt; // number of sections in table
8282

83-
OutBuffer* symbuf; // the symbol table
83+
OutBuffer* symbuf; // the symbol table
8484

8585
OutBuffer* syment_buf; // array of struct syment
8686

@@ -1704,14 +1704,6 @@ static if (0) // NOT_DONE
17041704
}
17051705
}
17061706

1707-
@trusted
1708-
private char* unsstr(uint value)
1709-
{
1710-
__gshared char[64] buffer;
1711-
1712-
snprintf (buffer.ptr, buffer.length, "%d", value);
1713-
return buffer.ptr;
1714-
}
17151707

17161708
/*******************************
17171709
* Mangle a name.

0 commit comments

Comments
 (0)