Skip to content

Commit

Permalink
Merge pull request swiftlang#61833 from zoecarver/astgen-fix-int-literal
Browse files Browse the repository at this point in the history
[astgen] Fix two use-after-frees.
  • Loading branch information
CodaFi authored Nov 1, 2022
2 parents a784c00 + 06d6c92 commit 8ca67c7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/AST/CASTBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,19 @@ void *SwiftIdentifierExpr_create(void *ctx, BridgedIdentifier base, void *loc) {
void *SwiftStringLiteralExpr_create(void *ctx, const uint8_t *_Nullable string,
long len, void *TokenLoc) {
ASTContext &Context = *static_cast<ASTContext *>(ctx);
return new (Context) StringLiteralExpr(
StringRef{reinterpret_cast<const char *>(string), size_t(len)},
getSourceLocFromPointer(TokenLoc));
auto stringRef = Context.AllocateCopy(
StringRef{reinterpret_cast<const char *>(string), size_t(len)});
return new (Context)
StringLiteralExpr(stringRef, getSourceLocFromPointer(TokenLoc));
}

void *SwiftIntegerLiteralExpr_create(void *ctx, const uint8_t *_Nullable string,
long len, void *TokenLoc) {
ASTContext &Context = *static_cast<ASTContext *>(ctx);
return new (Context) IntegerLiteralExpr(
StringRef{reinterpret_cast<const char *>(string), size_t(len)},
getSourceLocFromPointer(TokenLoc));
auto stringRef = Context.AllocateCopy(
StringRef{reinterpret_cast<const char *>(string), size_t(len)});
return new (Context)
IntegerLiteralExpr(stringRef, getSourceLocFromPointer(TokenLoc));
}

void *SwiftBooleanLiteralExpr_create(void *ctx, bool value, void *TokenLoc) {
Expand Down

0 comments on commit 8ca67c7

Please sign in to comment.