Skip to content

Fix compiler warnings #58

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

Merged
merged 5 commits into from
Mar 17, 2021
Merged
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "-Wall -Wparentheses -Winline -Wbad-function-cast -Wdisabled-optimization -Wextra")
else()
message(STATUS "MSVC compiler in use")
set(CMAKE_CXX_FLAGS "/Wall /W4")
set(CMAKE_CXX_FLAGS "/Wall /W4 /EHsc")
endif()

add_compile_definitions(NAPI_CPP_EXCEPTIONS)
Expand Down
1 change: 1 addition & 0 deletions src/MMBitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void destroyMMBitmap(MMBitmapRef bitmap)

void destroyMMBitmapBuffer(char * bitmapBuffer, void * hint)
{
(void)hint;
if (bitmapBuffer != NULL)
{
free(bitmapBuffer);
Expand Down
4 changes: 2 additions & 2 deletions src/MMBitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ MMBitmapRef copyMMBitmapFromPortion(MMBitmapRef source, MMRect rect);
#define MMBitmapPointInBounds(image, p) ((p).x < (image)->width && \
(p).y < (image)->height)
#define MMBitmapRectInBounds(image, r) \
(((r).origin.x + (r).size.width <= (image)->width) && \
((r).origin.y + (r).size.height <= (image)->height))
(((r).origin.x + (r).size.width <= (int64_t)(image)->width) && \
((r).origin.y + (r).size.height <= (int64_t)(image)->height))

#define MMBitmapGetBounds(image) MMRectMake(0, 0, image->width, image->height)

Expand Down
1 change: 1 addition & 0 deletions src/buffer_finalizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class BufferFinalizer
public:
void operator()(Napi::Env env, T *data)
{
(void)env;
if (data != nullptr)
{
delete data;
Expand Down
2 changes: 1 addition & 1 deletion src/deadbeef_rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ uint32_t deadbeef_generate_seed(void)
{
uint32_t t = (uint32_t)time(NULL);
uint32_t c = (uint32_t)clock();
return (t << 24) ^ (c << 11) ^ t ^ (size_t) &c;
return (uint32_t)((t << 24) ^ (c << 11) ^ t ^ (size_t) &c);
}
30 changes: 15 additions & 15 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ Napi::Number _keyToggle(const Napi::CallbackInfo &info)
MMKeyFlags flags = MOD_NONE;
MMKeyCode key;

bool down;
bool down = false;

//Get arguments from JavaScript.
std::string keyName = info[0].As<Napi::String>();
Expand Down Expand Up @@ -576,7 +576,7 @@ Napi::Number _typeStringDelayed(const Napi::CallbackInfo &info)
std::string stringToType = info[0].As<Napi::String>();
size_t cpm = info[1].As<Napi::Number>().Int32Value();

typeStringDelayed(stringToType.c_str(), cpm);
typeStringDelayed(stringToType.c_str(), (unsigned int)cpm);

return Napi::Number::New(env, 1);
}
Expand Down Expand Up @@ -613,8 +613,8 @@ Napi::Object _getScreenSize(const Napi::CallbackInfo &info)

//Create our return object.
Napi::Object obj = Napi::Object::New(env);
obj.Set(Napi::String::New(env, "width"), Napi::Number::New(env, displaySize.width));
obj.Set(Napi::String::New(env, "height"), Napi::Number::New(env, displaySize.height));
obj.Set(Napi::String::New(env, "width"), Napi::Number::New(env, (double)displaySize.width));
obj.Set(Napi::String::New(env, "height"), Napi::Number::New(env, (double)displaySize.height));

return obj;
}
Expand Down Expand Up @@ -660,7 +660,7 @@ Napi::Number _highlight(const Napi::CallbackInfo &info)
y = info[1].As<Napi::Number>().Int32Value();
width = info[2].As<Napi::Number>().Int32Value();
height = info[3].As<Napi::Number>().Int32Value();
duration = info[4].As<Napi::Number>().Int64Value();
duration = (int)info[4].As<Napi::Number>().Int64Value();
opacity = info[5].As<Napi::Number>().FloatValue();

highlight(x, y, width, height, duration, opacity);
Expand All @@ -673,7 +673,7 @@ Napi::Number _getActiveWindow(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();

WindowHandle windowHandle = getActiveWindow();
return Napi::Number::New(env, windowHandle);
return Napi::Number::New(env, (double)windowHandle);
}

Napi::Array _getWindows(const Napi::CallbackInfo &info) {
Expand All @@ -683,7 +683,7 @@ Napi::Array _getWindows(const Napi::CallbackInfo &info) {
auto arr = Napi::Array::New(env, windowHandles.size());

for (size_t idx = 0; idx < windowHandles.size(); ++idx) {
arr[idx] = windowHandles[idx];
arr[(uint32_t)idx] = windowHandles[idx];
}

return arr;
Expand All @@ -696,10 +696,10 @@ Napi::Object _getWindowRect(const Napi::CallbackInfo &info) {
MMRect windowRect = getWindowRect(windowHandle);

Napi::Object obj = Napi::Object::New(env);
obj.Set(Napi::String::New(env, "x"), Napi::Number::New(env, windowRect.origin.x));
obj.Set(Napi::String::New(env, "y"), Napi::Number::New(env, windowRect.origin.y));
obj.Set(Napi::String::New(env, "width"), Napi::Number::New(env, windowRect.size.width));
obj.Set(Napi::String::New(env, "height"), Napi::Number::New(env, windowRect.size.height));
obj.Set(Napi::String::New(env, "x"), Napi::Number::New(env, (double)windowRect.origin.x));
obj.Set(Napi::String::New(env, "y"), Napi::Number::New(env, (double)windowRect.origin.y));
obj.Set(Napi::String::New(env, "width"), Napi::Number::New(env, (double)windowRect.size.width));
obj.Set(Napi::String::New(env, "height"), Napi::Number::New(env, (double)windowRect.size.height));

return obj;
}
Expand Down Expand Up @@ -763,13 +763,13 @@ Napi::Object _captureScreen(const Napi::CallbackInfo &info)
throw Napi::Error::New(env, "Error: Failed to capture screen");
}

uint32_t bufferSize = bitmap->bytewidth * bitmap->height;
uint32_t bufferSize = (uint32_t)(bitmap->bytewidth * bitmap->height);
Napi::Buffer<char> buffer = Napi::Buffer<char>::New(env, (char *)bitmap->imageBuffer, bufferSize, finalizer);

Napi::Object obj = Napi::Object::New(env);
obj.Set(Napi::String::New(env, "width"), Napi::Number::New(env, bitmap->width));
obj.Set(Napi::String::New(env, "height"), Napi::Number::New(env, bitmap->height));
obj.Set(Napi::String::New(env, "byteWidth"), Napi::Number::New(env, bitmap->bytewidth));
obj.Set(Napi::String::New(env, "width"), Napi::Number::New(env, (double)bitmap->width));
obj.Set(Napi::String::New(env, "height"), Napi::Number::New(env, (double)bitmap->height));
obj.Set(Napi::String::New(env, "byteWidth"), Napi::Number::New(env, (double)bitmap->bytewidth));
obj.Set(Napi::String::New(env, "bitsPerPixel"), Napi::Number::New(env, bitmap->bitsPerPixel));
obj.Set(Napi::String::New(env, "bytesPerPixel"), Napi::Number::New(env, bitmap->bytesPerPixel));
obj.Set(Napi::String::New(env, "image"), buffer);
Expand Down
8 changes: 5 additions & 3 deletions src/win32/keypress.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void win32KeyEvent(int key, MMKeyFlags flags)

INPUT keyboardInput;
keyboardInput.type = INPUT_KEYBOARD;
keyboardInput.ki.wScan = scan;
keyboardInput.ki.wScan = (WORD)scan;
keyboardInput.ki.dwFlags = KEYEVENTF_SCANCODE | flags;
keyboardInput.ki.time = 0;
SendInput(1, &keyboardInput, sizeof(keyboardInput));
Expand Down Expand Up @@ -167,9 +167,11 @@ void typeString(const char *str)
c3 = (*str++) & 0x3F;
n = ((c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3;
}
else
continue; /* ignore invalid UTF-8 */

toggleUniKey(n, true);
toggleUniKey(n, false);
toggleUniKey((char)n, true);
toggleUniKey((char)n, false);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/win32/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
*/
void moveMouse(MMPoint point)
{
SetCursorPos (point.x, point.y);
SetCursorPos ((int)point.x, (int)point.y);
}

void dragMouse(MMPoint point, const MMMouseButton button)
{
(void)button;
moveMouse(point);
}

Expand Down
4 changes: 2 additions & 2 deletions src/win32/screengrab.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect)
(int)rect.size.width,
(int)rect.size.height,
screen,
rect.origin.x,
rect.origin.y,
(int)rect.origin.x,
(int)rect.origin.y,
SRCCOPY)) {

/* Error copying data. */
Expand Down