From dd630c1b36124e4010d609544f6bdeffb56ba947 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Mon, 5 Dec 2016 12:08:16 +0100 Subject: [PATCH 1/2] src: dummy case in node::RevertMessage for Windows Resolve warning on Windows build --- src/node_revert.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/node_revert.cc b/src/node_revert.cc index 48f03a89a3131e..877d05b28fbcc1 100644 --- a/src/node_revert.cc +++ b/src/node_revert.cc @@ -10,6 +10,11 @@ const char* RevertMessage(const unsigned int cve) { #define V(code, label, msg) case REVERT_ ## code: return label ": " msg; switch (cve) { REVERSIONS(V) +#ifdef _WIN32 + // Resolve warning on Windows build: + case 0xDEADBEEF: + return "deadbeef"; +#endif default: return "Unknown"; } From e28e6b3aad220c53f360fcc6c004c041ee0f6451 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Mon, 5 Dec 2016 20:40:21 +0100 Subject: [PATCH 2/2] src: resolve miscellaneous conversion warnings (Windows build) Some TBD POSSIBLE DATA LOSS scenarios marked. --- src/async-wrap.cc | 15 +++++++++++---- src/base64.h | 6 +++--- src/inspector_agent.cc | 4 +++- src/node.cc | 7 ++++++- src/node_buffer.cc | 6 ++++-- src/node_crypto.cc | 4 +++- src/node_file.cc | 12 +++++++++--- src/node_http_parser.cc | 2 +- src/node_i18n.cc | 3 ++- src/node_os.cc | 22 +++++++++++++++------- src/node_url.cc | 3 ++- src/string_search.h | 2 +- 12 files changed, 60 insertions(+), 26 deletions(-) diff --git a/src/async-wrap.cc b/src/async-wrap.cc index 42463bd22b31f4..3a86b864764fc2 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -203,7 +203,9 @@ void AsyncWrap::DestroyIdsCb(uv_idle_t* handle) { // Want each callback to be cleaned up after itself, instead of cleaning // them all up after the while() loop completes. HandleScope scope(env->isolate()); - Local argv = Number::New(env->isolate(), current_id); + // TBD POSSIBLE DATA LOSS: + Local argv = Number::New(env->isolate(), + static_cast(current_id)); MaybeLocal ret = fn->Call( env->context(), Undefined(env->isolate()), 1, &argv); @@ -252,14 +254,17 @@ AsyncWrap::AsyncWrap(Environment* env, HandleScope scope(env->isolate()); Local argv[] = { - Number::New(env->isolate(), get_uid()), + // TBD POSSIBLE DATA LOSS: + Number::New(env->isolate(), static_cast(get_uid())), Int32::New(env->isolate(), provider), Null(env->isolate()), Null(env->isolate()) }; if (parent != nullptr) { - argv[2] = Number::New(env->isolate(), parent->get_uid()); + // TBD POSSIBLE DATA LOSS: + argv[2] = Number::New(env->isolate(), + static_cast(parent->get_uid())); argv[3] = parent->object(); } @@ -295,7 +300,9 @@ Local AsyncWrap::MakeCallback(const Local cb, Local pre_fn = env()->async_hooks_pre_function(); Local post_fn = env()->async_hooks_post_function(); - Local uid = Number::New(env()->isolate(), get_uid()); + // TBD POSSIBLE DATA LOSS: + Local uid = Number::New(env()->isolate(), + static_cast(get_uid())); Local context = object(); Local domain; bool has_domain = false; diff --git a/src/base64.h b/src/base64.h index 64c4e330c0db84..35724e0ae57b03 100644 --- a/src/base64.h +++ b/src/base64.h @@ -61,8 +61,8 @@ size_t base64_decode_slow(char* dst, size_t dstlen, for (;;) { #define V(expr) \ while (i < srclen) { \ - const uint8_t c = src[i]; \ - lo = unbase64(c); \ + const uint8_t c = static_cast(src[i]); \ + lo = static_cast(unbase64(c)); \ i += 1; \ if (lo < 64) \ break; /* Legal character. */ \ @@ -75,7 +75,7 @@ size_t base64_decode_slow(char* dst, size_t dstlen, if (k >= dstlen) \ return k; \ hi = lo; - V(/* Nothing. */); + V(; /* Nothing. */); V(dst[k++] = ((hi & 0x3F) << 2) | ((lo & 0x30) >> 4)); V(dst[k++] = ((hi & 0x0F) << 4) | ((lo & 0x3C) >> 2)); V(dst[k++] = ((hi & 0x03) << 6) | ((lo & 0x3F) >> 0)); diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index fd7968ff68ced1..d1e435d52f0861 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -589,7 +589,9 @@ void AgentImpl::FatalException(v8::Local error, auto env = parent_env_; v8::Local context = env->context(); - int script_id = message->GetScriptOrigin().ScriptID()->Value(); + // TBD POSSIBLE DATA LOSS: + int script_id = + static_cast(message->GetScriptOrigin().ScriptID()->Value()); v8::Local stack_trace = message->GetStackTrace(); diff --git a/src/node.cc b/src/node.cc index e87bddcb6ff2cc..39b5757457f810 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2246,9 +2246,14 @@ void MemoryUsage(const FunctionCallbackInfo& args) { Number::New(env->isolate(), v8_heap_stats.total_heap_size()); Local heap_used = Number::New(env->isolate(), v8_heap_stats.used_heap_size()); + + const int64_t new_external_mem = + env->isolate()->AdjustAmountOfExternalAllocatedMemory(0); + + // TBD POSSIBLE DATA LOSS: Local external_mem = Number::New(env->isolate(), - env->isolate()->AdjustAmountOfExternalAllocatedMemory(0)); + static_cast(new_external_mem)); Local info = Object::New(env->isolate()); info->Set(env->rss_string(), Number::New(env->isolate(), rss)); diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 540de1827f9716..80c7d6d7990778 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -789,8 +789,10 @@ void WriteFloatGeneric(const FunctionCallbackInfo& args) { if (ts_obj_length > 0) CHECK_NE(ts_obj_data, nullptr); - T val = args[1]->NumberValue(env->context()).FromMaybe(0); - size_t offset = args[2]->IntegerValue(env->context()).FromMaybe(0); + // TBD POSSIBLE DATA LOSS: + T val = static_cast(args[1]->NumberValue(env->context()).FromMaybe(0)); + size_t offset = + static_cast(args[2]->IntegerValue(env->context()).FromMaybe(0)); size_t memcpy_num = sizeof(T); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 8f2f75048f7e9d..3a3016add8b870 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5543,7 +5543,9 @@ void RandomBytes(const FunctionCallbackInfo& args) { return env->ThrowRangeError("size is not a valid Smi"); Local obj = env->NewInternalFieldObject(); - RandomBytesRequest* req = new RandomBytesRequest(env, obj, size); + // TBD POSSIBLE DATA LOSS: + RandomBytesRequest* req = + new RandomBytesRequest(env, obj, static_cast(size)); if (args[1]->IsFunction()) { obj->Set(FIXED_ONE_BYTE_STRING(args.GetIsolate(), "ondone"), args[1]); diff --git a/src/node_file.cc b/src/node_file.cc index 0abb88088786ae..515722128f3082 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -439,8 +439,11 @@ Local BuildStatsObject(Environment* env, const uv_stat_t* s) { // Unsigned integers. It does not actually seem to be specified whether // uid and gid are unsigned or not, but in practice they are unsigned, // and Node’s (F)Chown functions do check their arguments for unsignedness. + // TBD POSSIBLE DATA LOSS: #define X(name) \ - Local name = Integer::NewFromUnsigned(env->isolate(), s->st_##name); \ + Local name = \ + Integer::NewFromUnsigned(env->isolate(), \ + static_cast(s->st_##name)); \ if (name.IsEmpty()) \ return Local(); \ @@ -454,8 +457,10 @@ Local BuildStatsObject(Environment* env, const uv_stat_t* s) { #undef X // Integers. + // TBD POSSIBLE DATA LOSS (Windows) #define X(name) \ - Local name = Integer::New(env->isolate(), s->st_##name); \ + Local name = Integer::New(env->isolate(), \ + static_cast(s->st_##name)); \ if (name.IsEmpty()) \ return Local(); \ @@ -575,11 +580,12 @@ static void InternalModuleReadFile(const FunctionCallbackInfo& args) { start = 3; // Skip UTF-8 BOM. } + // TBD POSSIBLE DATA LOSS: Local chars_string = String::NewFromUtf8(env->isolate(), &chars[start], String::kNormalString, - offset - start); + static_cast(offset - start)); args.GetReturnValue().Set(chars_string); } diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index f757cd6797058d..96fd042c32d383 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -294,7 +294,7 @@ class Parser : public AsyncWrap { return -1; } - return head_response->IntegerValue(); + return static_cast(head_response->IntegerValue()); } diff --git a/src/node_i18n.cc b/src/node_i18n.cc index a98fdca4d1bffd..135600a2a19557 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -115,7 +115,8 @@ struct Converter { conv = ucnv_open(name, &status); CHECK(U_SUCCESS(status)); if (sub != NULL) { - ucnv_setSubstChars(conv, sub, strlen(sub), &status); + // TBD POSSIBLE DATA LOSS: + ucnv_setSubstChars(conv, sub, static_cast(strlen(sub)), &status); } } diff --git a/src/node_os.cc b/src/node_os.cc index d8276f463d6625..509d278bff4e0c 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -124,16 +124,22 @@ static void GetCPUInfo(const FunctionCallbackInfo& args) { uv_cpu_info_t* ci = cpu_infos + i; Local times_info = Object::New(env->isolate()); + // TBD POSSIBLE DATA LOSS: times_info->Set(env->user_string(), - Number::New(env->isolate(), ci->cpu_times.user)); + Number::New(env->isolate(), + static_cast(ci->cpu_times.user))); times_info->Set(env->nice_string(), - Number::New(env->isolate(), ci->cpu_times.nice)); + Number::New(env->isolate(), + static_cast(ci->cpu_times.nice))); times_info->Set(env->sys_string(), - Number::New(env->isolate(), ci->cpu_times.sys)); + Number::New(env->isolate(), + static_cast(ci->cpu_times.sys))); times_info->Set(env->idle_string(), - Number::New(env->isolate(), ci->cpu_times.idle)); + Number::New(env->isolate(), + static_cast(ci->cpu_times.idle))); times_info->Set(env->irq_string(), - Number::New(env->isolate(), ci->cpu_times.irq)); + Number::New(env->isolate(), + static_cast(ci->cpu_times.irq))); Local cpu_info = Object::New(env->isolate()); cpu_info->Set(env->model_string(), @@ -151,7 +157,8 @@ static void GetCPUInfo(const FunctionCallbackInfo& args) { static void GetFreeMemory(const FunctionCallbackInfo& args) { - double amount = uv_get_free_memory(); + // TBD POSSIBLE DATA LOSS: + double amount = static_cast(uv_get_free_memory()); if (amount < 0) return; args.GetReturnValue().Set(amount); @@ -159,7 +166,8 @@ static void GetFreeMemory(const FunctionCallbackInfo& args) { static void GetTotalMemory(const FunctionCallbackInfo& args) { - double amount = uv_get_total_memory(); + // TBD POSSIBLE DATA LOSS: + double amount = static_cast(uv_get_total_memory()); if (amount < 0) return; args.GetReturnValue().Set(amount); diff --git a/src/node_url.cc b/src/node_url.cc index 7502461114a7b4..b04844941cea9c 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -341,7 +341,8 @@ namespace url { val = numbers[parts - 1]; for (int n = 0; n < parts - 1; n++) { double b = 3-n; - val += numbers[n] * pow(256, b); + // TBD POSSIBLE DATA LOSS: + val += static_cast(numbers[n] * pow(256, b)); } } diff --git a/src/string_search.h b/src/string_search.h index abc69edb87621d..3f9adb3899b0af 100644 --- a/src/string_search.h +++ b/src/string_search.h @@ -494,7 +494,7 @@ size_t StringSearch::BoyerMooreHorspoolSearch( const size_t subject_length = subject.length(); const size_t pattern_length = pattern.length(); int* char_occurrences = search->bad_char_table(); - int64_t badness = -pattern_length; + int64_t badness = -static_cast(pattern_length); // How bad we are doing without a good-suffix table. Char last_char = pattern[pattern_length - 1];