Skip to content

Commit 8ca67c7

Browse files
authored
Merge pull request #61833 from zoecarver/astgen-fix-int-literal
[astgen] Fix two use-after-frees.
2 parents a784c00 + 06d6c92 commit 8ca67c7

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/AST/CASTBridging.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,19 @@ void *SwiftIdentifierExpr_create(void *ctx, BridgedIdentifier base, void *loc) {
120120
void *SwiftStringLiteralExpr_create(void *ctx, const uint8_t *_Nullable string,
121121
long len, void *TokenLoc) {
122122
ASTContext &Context = *static_cast<ASTContext *>(ctx);
123-
return new (Context) StringLiteralExpr(
124-
StringRef{reinterpret_cast<const char *>(string), size_t(len)},
125-
getSourceLocFromPointer(TokenLoc));
123+
auto stringRef = Context.AllocateCopy(
124+
StringRef{reinterpret_cast<const char *>(string), size_t(len)});
125+
return new (Context)
126+
StringLiteralExpr(stringRef, getSourceLocFromPointer(TokenLoc));
126127
}
127128

128129
void *SwiftIntegerLiteralExpr_create(void *ctx, const uint8_t *_Nullable string,
129130
long len, void *TokenLoc) {
130131
ASTContext &Context = *static_cast<ASTContext *>(ctx);
131-
return new (Context) IntegerLiteralExpr(
132-
StringRef{reinterpret_cast<const char *>(string), size_t(len)},
133-
getSourceLocFromPointer(TokenLoc));
132+
auto stringRef = Context.AllocateCopy(
133+
StringRef{reinterpret_cast<const char *>(string), size_t(len)});
134+
return new (Context)
135+
IntegerLiteralExpr(stringRef, getSourceLocFromPointer(TokenLoc));
134136
}
135137

136138
void *SwiftBooleanLiteralExpr_create(void *ctx, bool value, void *TokenLoc) {

0 commit comments

Comments
 (0)