Skip to content

Commit

Permalink
Avoid warnings from Visual C++ code analysis with assertions and 'def…
Browse files Browse the repository at this point in the history
…ault' for switches.
  • Loading branch information
nyamatongwe committed Jun 2, 2022
1 parent 22777f4 commit 55a507f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lexlib/LexAccessor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using namespace Lexilla;
namespace Lexilla {

bool LexAccessor::MatchIgnoreCase(Sci_Position pos, const char *s) {
assert(s);
for (; *s; s++, pos++) {
if (*s != MakeLowerCase(SafeGetCharAt(pos))) {
return false;
Expand All @@ -29,7 +30,8 @@ bool LexAccessor::MatchIgnoreCase(Sci_Position pos, const char *s) {
}

void LexAccessor::GetRange(Sci_PositionU startPos_, Sci_PositionU endPos_, char *s, Sci_PositionU len) {
assert(startPos_ <= endPos_ && len != 0 && s != nullptr);
assert(s);
assert(startPos_ <= endPos_ && len != 0);
endPos_ = std::min(endPos_, startPos_ + len - 1);
len = endPos_ - startPos_;
if (startPos_ >= static_cast<Sci_PositionU>(startPos) && endPos_ <= static_cast<Sci_PositionU>(endPos)) {
Expand All @@ -42,6 +44,7 @@ void LexAccessor::GetRange(Sci_PositionU startPos_, Sci_PositionU endPos_, char
}

void LexAccessor::GetRangeLowered(Sci_PositionU startPos_, Sci_PositionU endPos_, char *s, Sci_PositionU len) {
assert(s);
GetRange(startPos_, endPos_, s, len);
while (*s) {
if (*s >= 'A' && *s <= 'Z') {
Expand Down
4 changes: 4 additions & 0 deletions lexlib/LexAccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class LexAccessor {
case 950:
case 1361:
encodingType = EncodingType::dbcs;
break;
default:
break;
}
}
char operator[](Sci_Position position) {
Expand Down Expand Up @@ -101,6 +104,7 @@ class LexAccessor {
return encodingType;
}
bool Match(Sci_Position pos, const char *s) {
assert(s);
for (int i=0; *s; i++) {
if (*s != SafeGetCharAt(pos+i))
return false;
Expand Down
2 changes: 2 additions & 0 deletions lexlib/OptionSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class OptionSet {
}
break;
}
default:
break;
}
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions lexlib/PropSetSimple.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Maintain a dictionary of properties

#include <cstdlib>
#include <cassert>
#include <cstring>

#include <string>
Expand Down Expand Up @@ -68,6 +69,7 @@ const char *PropSetSimple::Get(std::string_view key) const {

int PropSetSimple::GetInt(std::string_view key, int defaultValue) const {
const char *val = Get(key);
assert(val);
if (*val) {
return atoi(val);
}
Expand Down
1 change: 1 addition & 0 deletions lexlib/WordList.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace {
* after each word.
*/
std::unique_ptr<char *[]> ArrayFromWordList(char *wordlist, size_t slen, size_t *len, bool onlyLineEnds = false) {
assert(wordlist);
size_t words = 0;
// For rapid determination of whether a character is a separator, build
// a look up table.
Expand Down

0 comments on commit 55a507f

Please sign in to comment.