diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 49a83907fe6e2d..39727fcdd14179 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -34,8 +34,6 @@ #include #include -#define MIN(a, b) ((a) < (b) ? (a) : (b)) - #define THROW_AND_RETURN_UNLESS_BUFFER(env, obj) \ THROW_AND_RETURN_IF_NOT_BUFFER(env, obj, "argument") \ @@ -518,9 +516,9 @@ void Copy(const FunctionCallbackInfo &args) { if (source_end - source_start > target_length - target_start) source_end = source_start + target_length - target_start; - uint32_t to_copy = MIN(MIN(source_end - source_start, - target_length - target_start), - ts_obj_length - source_start); + uint32_t to_copy = std::min( + std::min(source_end - source_start, target_length - target_start), + ts_obj_length - source_start); memmove(target_data + target_start, ts_obj_data + source_start, to_copy); args.GetReturnValue().Set(to_copy); @@ -551,7 +549,8 @@ void Fill(const FunctionCallbackInfo& args) { if (Buffer::HasInstance(args[1])) { SPREAD_BUFFER_ARG(args[1], fill_obj); str_length = fill_obj_length; - memcpy(ts_obj_data + start, fill_obj_data, MIN(str_length, fill_length)); + memcpy( + ts_obj_data + start, fill_obj_data, std::min(str_length, fill_length)); goto start_fill; } @@ -572,7 +571,7 @@ void Fill(const FunctionCallbackInfo& args) { if (enc == UTF8) { str_length = str_obj->Utf8Length(env->isolate()); node::Utf8Value str(env->isolate(), args[1]); - memcpy(ts_obj_data + start, *str, MIN(str_length, fill_length)); + memcpy(ts_obj_data + start, *str, std::min(str_length, fill_length)); } else if (enc == UCS2) { str_length = str_obj->Length() * sizeof(uint16_t); @@ -580,7 +579,7 @@ void Fill(const FunctionCallbackInfo& args) { if (IsBigEndian()) SwapBytes16(reinterpret_cast(&str[0]), str_length); - memcpy(ts_obj_data + start, *str, MIN(str_length, fill_length)); + memcpy(ts_obj_data + start, *str, std::min(str_length, fill_length)); } else { // Write initial String to Buffer, then use that memory to copy remainder @@ -645,7 +644,7 @@ void StringWrite(const FunctionCallbackInfo& args) { THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[2], ts_obj_length - offset, &max_length)); - max_length = MIN(ts_obj_length - offset, max_length); + max_length = std::min(ts_obj_length - offset, max_length); if (max_length == 0) return args.GetReturnValue().Set(0); @@ -714,9 +713,9 @@ void CompareOffset(const FunctionCallbackInfo &args) { CHECK_LE(source_start, source_end); CHECK_LE(target_start, target_end); - size_t to_cmp = MIN(MIN(source_end - source_start, - target_end - target_start), - ts_obj_length - source_start); + size_t to_cmp = + std::min(std::min(source_end - source_start, target_end - target_start), + ts_obj_length - source_start); int val = normalizeCompareVal(to_cmp > 0 ? memcmp(ts_obj_data + source_start, @@ -736,7 +735,7 @@ void Compare(const FunctionCallbackInfo &args) { SPREAD_BUFFER_ARG(args[0], obj_a); SPREAD_BUFFER_ARG(args[1], obj_b); - size_t cmp_length = MIN(obj_a_length, obj_b_length); + size_t cmp_length = std::min(obj_a_length, obj_b_length); int val = normalizeCompareVal(cmp_length > 0 ? memcmp(obj_a_data, obj_b_data, cmp_length) : 0,