Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Commit

Permalink
Remove NTString; fix use-after-free memory
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdufault committed May 10, 2018
1 parent 7d4b7e2 commit 4d72ddc
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 71 deletions.
4 changes: 2 additions & 2 deletions src/clang_cursor.cc
Expand Up @@ -232,7 +232,7 @@ std::string ClangCursor::get_type_description() const {
return ::ToString(clang_getTypeSpelling(type));
}

NtString ClangCursor::get_comments() const {
std::string ClangCursor::get_comments() const {
CXSourceRange range = clang_Cursor_getCommentRange(cx_cursor);
if (clang_Range_isNull(range))
return {};
Expand Down Expand Up @@ -290,7 +290,7 @@ NtString ClangCursor::get_comments() const {
ret.pop_back();
if (ret.empty())
return {};
return static_cast<std::string_view>(ret);
return ret;
}

std::string ClangCursor::ToString() const {
Expand Down
3 changes: 1 addition & 2 deletions src/clang_cursor.h
@@ -1,6 +1,5 @@
#pragma once

#include "nt_string.h"
#include "position.h"

#include <clang-c/Index.h>
Expand Down Expand Up @@ -86,7 +85,7 @@ class ClangCursor {
bool is_valid_kind() const;

std::string get_type_description() const;
NtString get_comments() const;
std::string get_comments() const;

std::string ToString() const;

Expand Down
13 changes: 6 additions & 7 deletions src/indexer.h
Expand Up @@ -9,7 +9,6 @@
#include "language.h"
#include "lsp.h"
#include "maybe.h"
#include "nt_string.h"
#include "performance.h"
#include "position.h"
#include "project.h"
Expand Down Expand Up @@ -147,8 +146,8 @@ template <typename F>
struct TypeDefDefinitionData {
// General metadata.
std::string detailed_name;
NtString hover;
NtString comments;
std::string hover;
std::string comments;

// While a class/type can technically have a separate declaration/definition,
// it doesn't really happen in practice. The declaration never contains
Expand Down Expand Up @@ -246,8 +245,8 @@ template <typename F>
struct FuncDefDefinitionData {
// General metadata.
std::string detailed_name;
NtString hover;
NtString comments;
std::string hover;
std::string comments;
Maybe<Use> spell;
Maybe<Use> extent;

Expand Down Expand Up @@ -351,8 +350,8 @@ template <typename F>
struct VarDefDefinitionData {
// General metadata.
std::string detailed_name;
NtString hover;
NtString comments;
std::string hover;
std::string comments;
// TODO: definitions should be a list of ranges, since there can be more
// than one - when??
Maybe<Use> spell;
Expand Down
6 changes: 3 additions & 3 deletions src/messages/cquery_member_hierarchy.cc
Expand Up @@ -35,7 +35,7 @@ struct Out_CqueryMemberHierarchy
: public lsOutMessage<Out_CqueryMemberHierarchy> {
struct Entry {
QueryTypeId id;
std::string_view name;
std::string name;
std::string fieldName;
lsLocation location;
// For unexpanded nodes, this is an upper bound because some entities may be
Expand Down Expand Up @@ -110,7 +110,7 @@ bool Expand(MessageHandler* m,
if (detailed_name)
entry->name = def->detailed_name;
else
entry->name = def->ShortName();
entry->name = def->ShortName().to_string();
std::unordered_set<Usr> seen;
if (levels > 0) {
std::vector<const QueryType*> stack;
Expand Down Expand Up @@ -177,7 +177,7 @@ struct Handler_CqueryMemberHierarchy
Out_CqueryMemberHierarchy::Entry entry;
// Not type, |id| is invalid.
if (detailed_name)
entry.name = def->DetailedName(false);
entry.name = def->DetailedName(false).to_string();
else
entry.name = std::string(def->ShortName());
if (def->spell) {
Expand Down
43 changes: 0 additions & 43 deletions src/nt_string.h

This file was deleted.

10 changes: 0 additions & 10 deletions src/serializer.cc
Expand Up @@ -132,16 +132,6 @@ void Reflect(Writer& visitor, std::string_view& data) {
visitor.String(&data[0], (rapidjson::SizeType)data.size());
}

void Reflect(Reader& visitor, NtString& value) {
if (!visitor.IsString())
throw std::invalid_argument("std::string");
value = visitor.GetString();
}
void Reflect(Writer& visitor, NtString& value) {
const char* s = value.c_str();
visitor.String(s ? s : "");
}

void Reflect(Reader& visitor, JsonNull& value) {
visitor.GetNull();
}
Expand Down
4 changes: 0 additions & 4 deletions src/serializer.h
@@ -1,7 +1,6 @@
#pragma once

#include "maybe.h"
#include "nt_string.h"
#include "port.h"

#include <macro_map.h>
Expand Down Expand Up @@ -179,9 +178,6 @@ void Reflect(Writer& visitor, std::string& value);
void Reflect(Reader& visitor, std::string_view& view);
void Reflect(Writer& visitor, std::string_view& view);

void Reflect(Reader& visitor, NtString& value);
void Reflect(Writer& visitor, NtString& value);

void Reflect(Reader& visitor, JsonNull& value);
void Reflect(Writer& visitor, JsonNull& value);

Expand Down

0 comments on commit 4d72ddc

Please sign in to comment.