Skip to content

[lldb] Fix logic error in AppleObjCTypeEncodingParser #137067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "clang/Basic/TargetInfo.h"

#include <optional>
#include <vector>

using namespace lldb_private;
Expand All @@ -41,13 +42,17 @@ std::string AppleObjCTypeEncodingParser::ReadStructName(StringLexer &type) {
return std::string(buffer.GetString());
}

std::string AppleObjCTypeEncodingParser::ReadQuotedString(StringLexer &type) {
std::optional<std::string>
AppleObjCTypeEncodingParser::ReadQuotedString(StringLexer &type) {
if (!type.HasAtLeast(1))
return std::nullopt;

StreamString buffer;
while (type.HasAtLeast(1) && type.Peek() != '"')
while (type.Peek() != '"') {
buffer.Printf("%c", type.Next());
StringLexer::Character next = type.Next();
UNUSED_IF_ASSERT_DISABLED(next);
assert(next == '"');
if (!type.HasAtLeast(1))
return std::nullopt;
}
return std::string(buffer.GetString());
}

Expand All @@ -70,10 +75,12 @@ AppleObjCTypeEncodingParser::ReadStructElement(TypeSystemClang &ast_ctx,
StringLexer &type,
bool for_expression) {
StructElement retval;
if (type.NextIf('"'))
retval.name = ReadQuotedString(type);
if (!type.NextIf('"'))
return retval;
if (type.NextIf('"')) {
if (auto maybe_name = ReadQuotedString(type))
retval.name = *maybe_name;
else
return retval;
}
uint32_t bitfield_size = 0;
retval.type = BuildType(ast_ctx, type, for_expression, &bitfield_size);
retval.bitfield = bitfield_size;
Expand Down Expand Up @@ -198,7 +205,10 @@ clang::QualType AppleObjCTypeEncodingParser::BuildObjCObjectPointerType(
// quoted string is a class name. - If we see anything else, the quoted
// string is a field name and we push it back onto type.

name = ReadQuotedString(type);
if (auto maybe_name = ReadQuotedString(type))
name = *maybe_name;
else
return clang::QualType();

if (type.HasAtLeast(1)) {
switch (type.Peek()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AppleObjCTypeEncodingParser : public ObjCLanguageRuntime::EncodingToType {

uint32_t ReadNumber(StringLexer &type);

std::string ReadQuotedString(StringLexer &type);
std::optional<std::string> ReadQuotedString(StringLexer &type);

ObjCLanguageRuntime &m_runtime;
};
Expand Down
Loading