Skip to content

explicit comparison instead of relying on truthy/falsey #11

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/bindings/string-conversion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Local<String> string_conversion::string_to_js(const u16string &text, const char
).ToLocal(&result)) {
return result;
} else {
if (!failure_message) failure_message = "Couldn't convert text to a String";
if (failure_message == nullptr) failure_message = "Couldn't convert text to a String";
Nan::ThrowError(failure_message);
return Nan::New<String>("").ToLocalChecked();
}
Expand All @@ -47,7 +47,7 @@ Local<String> string_conversion::char_to_js(const uint16_t c, const char *failur
if (Nan::New<String>(&c, 1).ToLocal(&result)) {
return result;
} else {
if (!failure_message) failure_message = "Couldn't convert character to a String";
if (failure_message == nullptr) failure_message = "Couldn't convert character to a String";
Nan::ThrowError(failure_message);
return Nan::New<String>("").ToLocalChecked();
}
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/text-buffer-snapshot-wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TextBufferSnapshotWrapper::TextBufferSnapshotWrapper(Local<Object> js_buffer, vo
}

TextBufferSnapshotWrapper::~TextBufferSnapshotWrapper() {
if (snapshot) {
if (snapshot != nullptr) {
delete reinterpret_cast<TextBuffer::Snapshot *>(snapshot);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/encoding-conversion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ EncodingConversion::EncodingConversion(int mode, void *data) :
data{data}, mode{mode} {}

EncodingConversion::~EncodingConversion() {
if (data) iconv_close(data);
if (data != nullptr) iconv_close(data);
}

int EncodingConversion::convert(
Expand Down Expand Up @@ -149,7 +149,7 @@ bool EncodingConversion::decode(u16string &string, FILE *stream,
for (;;) {
size_t bytes_to_read = input_vector.size() - bytes_left_over;
size_t bytes_read = fread(input_buffer + bytes_left_over, 1, bytes_to_read, stream);
if (bytes_read < bytes_to_read && ferror(stream)) return false;
if (bytes_read < bytes_to_read && (ferror(stream) != 0)) return false;
size_t bytes_to_append = bytes_left_over + bytes_read;
if (bytes_to_append == 0) break;

Expand Down Expand Up @@ -259,7 +259,7 @@ bool EncodingConversion::encode(const u16string &string, size_t start_offset,
}
}
size_t bytes_written = fwrite(output_buffer, 1, bytes_encoded, stream);
if (bytes_written < bytes_encoded && ferror(stream)) return false;
if (bytes_written < bytes_encoded && (ferror(stream) != 0)) return false;
}

return true;
Expand Down
8 changes: 4 additions & 4 deletions src/core/libmba-diff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static int _find_middle_snake(
}
_setv(ctx, k, 0, x);

if (odd && k >= (delta - (d - 1)) && k <= (delta + (d - 1))) {
if ((odd != 0) && k >= (delta - (d - 1)) && k <= (delta + (d - 1))) {
if (x >= RV(k)) {
ms->u = x;
ms->v = y;
Expand Down Expand Up @@ -153,7 +153,7 @@ static int _find_middle_snake(
}
_setv(ctx, kr, 1, x);

if (!odd && kr >= -d && kr <= d) {
if ((odd == 0) && kr >= -d && kr <= d) {
if (x <= FV(kr)) {
ms->x = x;
ms->y = y;
Expand All @@ -172,7 +172,7 @@ static void _edit(struct _ctx *ctx, diff_op op, int off, int len) {
// Add an edit to the SES (or coalesce if the op is the same)
auto *e = &ctx->ses->back();
if (e->op != op) {
if (e->op) {
if (e->op != 0) {
ctx->ses->push_back(diff_edit{});
e = &ctx->ses->back();
}
Expand Down Expand Up @@ -267,7 +267,7 @@ int diff(const char16_t *a, uint32_t n, const char16_t *b, uint32_t m,
int dmax, vector<diff_edit> *ses) {
struct _ctx ctx;
ctx.ses = ses;
ctx.dmax = dmax ? dmax : INT_MAX;
ctx.dmax = dmax != 0 ? dmax : INT_MAX;
ses->push_back(diff_edit{static_cast<diff_op>(0), 0, 0});

uint32_t common_prefix_length = 0;
Expand Down
Loading