Compare commits

..

1 Commits

Author SHA1 Message Date
7ad8354886 Define feature test macros in common.h
This enables necessary functions once for all.

As a consequence, define common.h before any other header.
2021-01-08 19:23:02 +01:00
23 changed files with 130 additions and 149 deletions

View File

@ -2,7 +2,6 @@ src = [
'src/main.c',
'src/adb.c',
'src/cli.c',
'src/compat.c',
'src/control_msg.c',
'src/controller.c',
'src/decoder.c',
@ -32,12 +31,6 @@ else
src += [ 'src/sys/unix/process.c' ]
endif
check_functions = [
'strdup'
]
cc = meson.get_compiler('c')
if not get_option('crossbuild_windows')
# native build
@ -51,6 +44,8 @@ if not get_option('crossbuild_windows')
else
# cross-compile mingw32 build (from Linux to Windows)
cc = meson.get_compiler('c')
prebuilt_sdl2 = meson.get_cross_property('prebuilt_sdl2')
sdl2_bin_dir = meson.current_source_dir() + '/../prebuilt-deps/' + prebuilt_sdl2 + '/bin'
sdl2_lib_dir = meson.current_source_dir() + '/../prebuilt-deps/' + prebuilt_sdl2 + '/lib'
@ -85,19 +80,14 @@ else
endif
cc = meson.get_compiler('c')
if host_machine.system() == 'windows'
dependencies += cc.find_library('ws2_32')
endif
conf = configuration_data()
foreach f : check_functions
if cc.has_function(f)
define = 'HAVE_' + f.underscorify().to_upper()
conf.set(define, true)
endif
endforeach
# expose the build type
conf.set('NDEBUG', get_option('buildtype') != 'debug')

View File

@ -173,7 +173,7 @@ adb_push(const char *serial, const char *local, const char *remote) {
}
remote = strquote(remote);
if (!remote) {
free((void *) local);
SDL_free((void *) local);
return PROCESS_NONE;
}
#endif
@ -182,8 +182,8 @@ adb_push(const char *serial, const char *local, const char *remote) {
process_t proc = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
#ifdef __WINDOWS__
free((void *) remote);
free((void *) local);
SDL_free((void *) remote);
SDL_free((void *) local);
#endif
return proc;
@ -204,7 +204,7 @@ adb_install(const char *serial, const char *local) {
process_t proc = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
#ifdef __WINDOWS__
free((void *) local);
SDL_free((void *) local);
#endif
return proc;

View File

@ -1,14 +0,0 @@
#include "compat.h"
#include "config.h"
#ifndef HAVE_STRDUP
char *strdup(const char *s) {
size_t size = strlen(s) + 1;
char *dup = malloc(size);
if (dup) {
memcpy(dup, s, size);
}
return dup;
}
#endif

View File

@ -56,8 +56,4 @@
# define SCRCPY_SDL_HAS_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR
#endif
#ifdef HAVE_STRDUP
char *strdup(const char *s);
#endif
#endif

View File

@ -1,7 +1,6 @@
#include "control_msg.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "util/buffer_util.h"
@ -94,10 +93,10 @@ void
control_msg_destroy(struct control_msg *msg) {
switch (msg->type) {
case CONTROL_MSG_TYPE_INJECT_TEXT:
free(msg->inject_text.text);
SDL_free(msg->inject_text.text);
break;
case CONTROL_MSG_TYPE_SET_CLIPBOARD:
free(msg->set_clipboard.text);
SDL_free(msg->set_clipboard.text);
break;
default:
// do nothing

View File

@ -50,7 +50,7 @@ struct control_msg {
enum android_metastate metastate;
} inject_keycode;
struct {
char *text; // owned, to be freed by free()
char *text; // owned, to be freed by SDL_free()
} inject_text;
struct {
enum android_motionevent_action action;
@ -65,7 +65,7 @@ struct control_msg {
int32_t vscroll;
} inject_scroll_event;
struct {
char *text; // owned, to be freed by free()
char *text; // owned, to be freed by SDL_free()
bool paste;
} set_clipboard;
struct {

View File

@ -60,12 +60,12 @@ static bool
process_msg(struct controller *controller,
const struct control_msg *msg) {
static unsigned char serialized_msg[CONTROL_MSG_MAX_SIZE];
size_t length = control_msg_serialize(msg, serialized_msg);
int length = control_msg_serialize(msg, serialized_msg);
if (!length) {
return false;
}
int w = net_send_all(controller->control_socket, serialized_msg, length);
return (size_t) w == length;
return w == length;
}
static int

View File

@ -1,6 +1,5 @@
#include "device_msg.h"
#include <stdlib.h>
#include <string.h>
#include "util/buffer_util.h"
@ -21,7 +20,7 @@ device_msg_deserialize(const unsigned char *buf, size_t len,
if (clipboard_len > len - 5) {
return 0; // not available
}
char *text = malloc(clipboard_len + 1);
char *text = SDL_malloc(clipboard_len + 1);
if (!text) {
LOGW("Could not allocate text for clipboard");
return -1;
@ -43,6 +42,6 @@ device_msg_deserialize(const unsigned char *buf, size_t len,
void
device_msg_destroy(struct device_msg *msg) {
if (msg->type == DEVICE_MSG_TYPE_CLIPBOARD) {
free(msg->clipboard.text);
SDL_free(msg->clipboard.text);
}
}

View File

@ -19,7 +19,7 @@ struct device_msg {
enum device_msg_type type;
union {
struct {
char *text; // owned, to be freed by free()
char *text; // owned, to be freed by SDL_free()
} clipboard;
};
};

View File

@ -11,7 +11,7 @@
static void
file_handler_request_destroy(struct file_handler_request *req) {
free(req->file);
SDL_free(req->file);
}
bool
@ -30,7 +30,7 @@ file_handler_init(struct file_handler *file_handler, const char *serial,
}
if (serial) {
file_handler->serial = strdup(serial);
file_handler->serial = SDL_strdup(serial);
if (!file_handler->serial) {
LOGW("Could not strdup serial");
SDL_DestroyCond(file_handler->event_cond);
@ -56,7 +56,7 @@ void
file_handler_destroy(struct file_handler *file_handler) {
SDL_DestroyCond(file_handler->event_cond);
SDL_DestroyMutex(file_handler->mutex);
free(file_handler->serial);
SDL_free(file_handler->serial);
struct file_handler_request req;
while (cbuf_take(&file_handler->queue, &req)) {
@ -135,13 +135,13 @@ run_file_handler(void *data) {
mutex_unlock(file_handler->mutex);
if (req.action == ACTION_INSTALL_APK) {
if (process_check_success(process, "adb install", false)) {
if (process_check_success(process, "adb install")) {
LOGI("%s successfully installed", req.file);
} else {
LOGE("Failed to install %s", req.file);
}
} else {
if (process_check_success(process, "adb push", false)) {
if (process_check_success(process, "adb push")) {
LOGI("%s successfully pushed to %s", req.file,
file_handler->push_target);
} else {
@ -150,14 +150,6 @@ run_file_handler(void *data) {
}
}
mutex_lock(file_handler->mutex);
// Close the process (it is necessary already terminated)
// Execute this call with mutex locked to avoid race conditions with
// file_handler_stop()
process_close(file_handler->current_process);
file_handler->current_process = PROCESS_NONE;
mutex_unlock(file_handler->mutex);
file_handler_request_destroy(&req);
}
return 0;
@ -184,8 +176,10 @@ file_handler_stop(struct file_handler *file_handler) {
cond_signal(file_handler->event_cond);
if (file_handler->current_process != PROCESS_NONE) {
if (!process_terminate(file_handler->current_process)) {
LOGW("Could not terminate push/install process");
LOGW("Could not terminate install process");
}
process_wait(file_handler->current_process, NULL);
file_handler->current_process = PROCESS_NONE;
}
mutex_unlock(file_handler->mutex);
}

View File

@ -50,7 +50,7 @@ file_handler_stop(struct file_handler *file_handler);
void
file_handler_join(struct file_handler *file_handler);
// take ownership of file, and will free() it
// take ownership of file, and will SDL_free() it
bool
file_handler_request(struct file_handler *file_handler,
file_handler_action_t action,

View File

@ -190,20 +190,13 @@ set_device_clipboard(struct controller *controller, bool paste) {
return;
}
char *text_dup = strdup(text);
SDL_free(text);
if (!text_dup) {
LOGW("Could not strdup input text");
return;
}
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_SET_CLIPBOARD;
msg.set_clipboard.text = text_dup;
msg.set_clipboard.text = text;
msg.set_clipboard.paste = paste;
if (!controller_push_msg(controller, &msg)) {
free(text_dup);
SDL_free(text);
LOGW("Could not request 'set device clipboard'");
}
}
@ -249,18 +242,11 @@ clipboard_paste(struct controller *controller) {
return;
}
char *text_dup = strdup(text);
SDL_free(text);
if (!text_dup) {
LOGW("Could not strdup input text");
return;
}
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_INJECT_TEXT;
msg.inject_text.text = text_dup;
msg.inject_text.text = text;
if (!controller_push_msg(controller, &msg)) {
free(text_dup);
SDL_free(text);
LOGW("Could not request 'paste clipboard'");
}
}
@ -305,13 +291,13 @@ input_manager_process_text_input(struct input_manager *im,
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_INJECT_TEXT;
msg.inject_text.text = strdup(event->text);
msg.inject_text.text = SDL_strdup(event->text);
if (!msg.inject_text.text) {
LOGW("Could not strdup input text");
return;
}
if (!controller_push_msg(im->controller, &msg)) {
free(msg.inject_text.text);
SDL_free(msg.inject_text.text);
LOGW("Could not request 'inject text'");
}
}

View File

@ -27,7 +27,7 @@ find_muxer(const char *name) {
static struct record_packet *
record_packet_new(const AVPacket *packet) {
struct record_packet *rec = malloc(sizeof(*rec));
struct record_packet *rec = SDL_malloc(sizeof(*rec));
if (!rec) {
return NULL;
}
@ -37,7 +37,7 @@ record_packet_new(const AVPacket *packet) {
av_init_packet(&rec->packet);
if (av_packet_ref(&rec->packet, packet)) {
free(rec);
SDL_free(rec);
return NULL;
}
return rec;
@ -46,7 +46,7 @@ record_packet_new(const AVPacket *packet) {
static void
record_packet_delete(struct record_packet *rec) {
av_packet_unref(&rec->packet);
free(rec);
SDL_free(rec);
}
static void
@ -63,7 +63,7 @@ recorder_init(struct recorder *recorder,
const char *filename,
enum sc_record_format format,
struct size declared_frame_size) {
recorder->filename = strdup(filename);
recorder->filename = SDL_strdup(filename);
if (!recorder->filename) {
LOGE("Could not strdup filename");
return false;
@ -72,7 +72,7 @@ recorder_init(struct recorder *recorder,
recorder->mutex = SDL_CreateMutex();
if (!recorder->mutex) {
LOGC("Could not create mutex");
free(recorder->filename);
SDL_free(recorder->filename);
return false;
}
@ -80,7 +80,7 @@ recorder_init(struct recorder *recorder,
if (!recorder->queue_cond) {
LOGC("Could not create cond");
SDL_DestroyMutex(recorder->mutex);
free(recorder->filename);
SDL_free(recorder->filename);
return false;
}
@ -99,7 +99,7 @@ void
recorder_destroy(struct recorder *recorder) {
SDL_DestroyCond(recorder->queue_cond);
SDL_DestroyMutex(recorder->mutex);
free(recorder->filename);
SDL_free(recorder->filename);
}
static const char *

View File

@ -286,7 +286,7 @@ av_log_callback(void *avcl, int level, const char *fmt, va_list vl) {
if (priority == 0) {
return;
}
char *local_fmt = malloc(strlen(fmt) + 10);
char *local_fmt = SDL_malloc(strlen(fmt) + 10);
if (!local_fmt) {
LOGC("Could not allocate string");
return;
@ -295,7 +295,7 @@ av_log_callback(void *avcl, int level, const char *fmt, va_list vl) {
strcpy(local_fmt, "[FFmpeg] ");
strcpy(local_fmt + 9, fmt);
SDL_LogMessageV(SDL_LOG_CATEGORY_VIDEO, priority, local_fmt, vl);
free(local_fmt);
SDL_free(local_fmt);
}
bool

View File

@ -33,7 +33,7 @@ get_server_path(void) {
#ifdef __WINDOWS__
char *server_path = utf8_from_wide_char(server_path_env);
#else
char *server_path = strdup(server_path_env);
char *server_path = SDL_strdup(server_path_env);
#endif
if (!server_path) {
LOGE("Could not allocate memory");
@ -45,7 +45,7 @@ get_server_path(void) {
#ifndef PORTABLE
LOGD("Using server: " DEFAULT_SERVER_PATH);
char *server_path = strdup(DEFAULT_SERVER_PATH);
char *server_path = SDL_strdup(DEFAULT_SERVER_PATH);
if (!server_path) {
LOGE("Could not allocate memory");
return NULL;
@ -67,11 +67,11 @@ get_server_path(void) {
// sizeof(SERVER_FILENAME) gives statically the size including the null byte
size_t len = dirlen + 1 + sizeof(SERVER_FILENAME);
char *server_path = malloc(len);
char *server_path = SDL_malloc(len);
if (!server_path) {
LOGE("Could not alloc server path string, "
"using " SERVER_FILENAME " from current directory");
free(executable_path);
SDL_free(executable_path);
return SERVER_FILENAME;
}
@ -80,7 +80,7 @@ get_server_path(void) {
memcpy(&server_path[dirlen + 1], SERVER_FILENAME, sizeof(SERVER_FILENAME));
// the final null byte has been copied with SERVER_FILENAME
free(executable_path);
SDL_free(executable_path);
LOGD("Using server (portable): %s", server_path);
return server_path;
@ -95,36 +95,36 @@ push_server(const char *serial) {
}
if (!is_regular_file(server_path)) {
LOGE("'%s' does not exist or is not a regular file\n", server_path);
free(server_path);
SDL_free(server_path);
return false;
}
process_t process = adb_push(serial, server_path, DEVICE_SERVER_PATH);
free(server_path);
return process_check_success(process, "adb push", true);
SDL_free(server_path);
return process_check_success(process, "adb push");
}
static bool
enable_tunnel_reverse(const char *serial, uint16_t local_port) {
process_t process = adb_reverse(serial, SOCKET_NAME, local_port);
return process_check_success(process, "adb reverse", true);
return process_check_success(process, "adb reverse");
}
static bool
disable_tunnel_reverse(const char *serial) {
process_t process = adb_reverse_remove(serial, SOCKET_NAME);
return process_check_success(process, "adb reverse --remove", true);
return process_check_success(process, "adb reverse --remove");
}
static bool
enable_tunnel_forward(const char *serial, uint16_t local_port) {
process_t process = adb_forward(serial, local_port, SOCKET_NAME);
return process_check_success(process, "adb forward", true);
return process_check_success(process, "adb forward");
}
static bool
disable_tunnel_forward(const char *serial, uint16_t local_port) {
process_t process = adb_forward_remove(serial, local_port);
return process_check_success(process, "adb forward --remove", true);
return process_check_success(process, "adb forward --remove");
}
static bool
@ -391,7 +391,7 @@ server_init(struct server *server) {
static int
run_wait_server(void *data) {
struct server *server = data;
process_wait(server->process, false); // ignore exit code
process_wait_noclose(server->process, NULL); // ignore exit code
mutex_lock(server->mutex);
server->process_terminated = true;
@ -416,7 +416,7 @@ server_start(struct server *server, const char *serial,
server->port_range = params->port_range;
if (serial) {
server->serial = strdup(serial);
server->serial = SDL_strdup(serial);
if (!server->serial) {
return false;
}
@ -447,7 +447,7 @@ server_start(struct server *server, const char *serial,
SDL_CreateThread(run_wait_server, "wait-server", server);
if (!server->wait_server_thread) {
process_terminate(server->process);
process_wait(server->process, true); // ignore exit code
process_wait(server->process, NULL); // ignore exit code
goto error2;
}
@ -466,7 +466,7 @@ error2:
}
disable_tunnel(server);
error1:
free(server->serial);
SDL_free(server->serial);
return false;
}
@ -561,7 +561,7 @@ server_stop(struct server *server) {
void
server_destroy(struct server *server) {
free(server->serial);
SDL_free(server->serial);
SDL_DestroyCond(server->process_terminated_cond);
SDL_DestroyMutex(server->mutex);
}

View File

@ -118,11 +118,11 @@ process_terminate(pid_t pid) {
(int) pid);
abort();
}
return kill(pid, SIGKILL) != -1;
return kill(pid, SIGTERM) != -1;
}
exit_code_t
process_wait(pid_t pid, bool close) {
static bool
process_wait_internal(pid_t pid, int *exit_code, bool close) {
int code;
int options = WEXITED;
if (!close) {
@ -133,16 +133,29 @@ process_wait(pid_t pid, bool close) {
int r = waitid(P_PID, pid, &info, options);
if (r == -1 || info.si_code != CLD_EXITED) {
// could not wait, or exited unexpectedly, probably by a signal
code = NO_EXIT_CODE;
code = -1;
} else {
code = info.si_status;
}
return code;
if (exit_code) {
*exit_code = code;
}
return !code;
}
bool
process_wait(pid_t pid, int *exit_code) {
return process_wait_internal(pid, exit_code, true);
}
bool
process_wait_noclose(pid_t pid, int *exit_code) {
return process_wait_internal(pid, exit_code, false);
}
void
process_close(pid_t pid) {
process_wait(pid, true); // ignore exit code
process_wait_internal(pid, NULL, true);
}
char *
@ -156,7 +169,7 @@ get_executable_path(void) {
return NULL;
}
buf[len] = '\0';
return strdup(buf);
return SDL_strdup(buf);
#else
// in practice, we only need this feature for portable builds, only used on
// Windows, so we don't care implementing it for every platform

View File

@ -41,7 +41,7 @@ process_execute(const char *const argv[], HANDLE *handle) {
if (!CreateProcessW(NULL, wide, NULL, NULL, FALSE, 0, NULL, NULL, &si,
&pi)) {
free(wide);
SDL_free(wide);
*handle = NULL;
if (GetLastError() == ERROR_FILE_NOT_FOUND) {
return PROCESS_ERROR_MISSING_BINARY;
@ -49,7 +49,7 @@ process_execute(const char *const argv[], HANDLE *handle) {
return PROCESS_ERROR_GENERIC;
}
free(wide);
SDL_free(wide);
*handle = pi.hProcess;
return PROCESS_SUCCESS;
}
@ -59,18 +59,31 @@ process_terminate(HANDLE handle) {
return TerminateProcess(handle, 1);
}
exit_code_t
process_wait(HANDLE handle, bool close) {
static bool
process_wait_internal(HANDLE handle, DWORD *exit_code, bool close) {
DWORD code;
if (WaitForSingleObject(handle, INFINITE) != WAIT_OBJECT_0
|| !GetExitCodeProcess(handle, &code)) {
// could not wait or retrieve the exit code
code = NO_EXIT_CODE; // max value, it's unsigned
code = -1; // max value, it's unsigned
}
if (exit_code) {
*exit_code = code;
}
if (close) {
CloseHandle(handle);
}
return code;
return !code;
}
bool
process_wait(HANDLE handle, DWORD *exit_code) {
return process_wait_internal(handle, exit_code, true);
}
bool
process_wait_noclose(HANDLE handle, DWORD *exit_code) {
return process_wait_internal(handle, exit_code, false);
}
void
@ -105,7 +118,7 @@ is_regular_file(const char *path) {
struct _stat path_stat;
int r = _wstat(wide_path, &path_stat);
free(wide_path);
SDL_free(wide_path);
if (r) {
perror("stat");

View File

@ -33,7 +33,7 @@ buffer_read16be(const uint8_t *buf) {
static inline uint32_t
buffer_read32be(const uint8_t *buf) {
return ((uint32_t) buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
}
static inline uint64_t

View File

@ -3,13 +3,13 @@
#include "log.h"
bool
process_check_success(process_t proc, const char *name, bool close) {
process_check_success(process_t proc, const char *name) {
if (proc == PROCESS_NONE) {
LOGE("Could not execute \"%s\"", name);
return false;
}
exit_code_t exit_code = process_wait(proc, close);
if (exit_code) {
exit_code_t exit_code;
if (!process_wait(proc, &exit_code)) {
if (exit_code != NO_EXIT_CODE) {
LOGE("\"%s\" returned with value %" PRIexitcode, name, exit_code);
} else {

View File

@ -47,21 +47,23 @@ bool
process_terminate(process_t pid);
// wait and close the process (like waitpid())
// the "close" flag indicates if the process must be "closed" (reaped)
// (passing false is equivalent to enable WNOWAIT in waitid())
exit_code_t
process_wait(process_t pid, bool close);
bool
process_wait(process_t pid, exit_code_t *exit_code);
// wait (but does not close) the process (waitid() with WNOWAIT)
bool
process_wait_noclose(process_t pid, exit_code_t *exit_code);
// close the process
//
// Semantically, process_wait(close) = process_wait(noclose) + process_close
// Semantically, process_wait = process_wait_noclose + process_close.
void
process_close(process_t pid);
// convenience function to wait for a successful process execution
// automatically log process errors with the provided process name
bool
process_check_success(process_t proc, const char *name, bool close);
process_check_success(process_t proc, const char *name);
#ifndef _WIN32
// only used to find package manager, not implemented for Windows
@ -70,7 +72,7 @@ search_executable(const char *file);
#endif
// return the absolute path of the executable (the scrcpy binary)
// may be NULL on error; to be freed by free()
// may be NULL on error; to be freed by SDL_free
char *
get_executable_path(void);

View File

@ -10,6 +10,8 @@
# include <tchar.h>
#endif
#include <SDL2/SDL_stdinc.h>
size_t
xstrncpy(char *dest, const char *src, size_t n) {
size_t i;
@ -47,7 +49,7 @@ truncated:
char *
strquote(const char *src) {
size_t len = strlen(src);
char *quoted = malloc(len + 3);
char *quoted = SDL_malloc(len + 3);
if (!quoted) {
return NULL;
}
@ -165,7 +167,7 @@ utf8_to_wide_char(const char *utf8) {
return NULL;
}
wchar_t *wide = malloc(len * sizeof(wchar_t));
wchar_t *wide = SDL_malloc(len * sizeof(wchar_t));
if (!wide) {
return NULL;
}
@ -181,7 +183,7 @@ utf8_from_wide_char(const wchar_t *ws) {
return NULL;
}
char *utf8 = malloc(len);
char *utf8 = SDL_malloc(len);
if (!utf8) {
return NULL;
}

View File

@ -17,7 +17,7 @@ static void test_serialize_inject_keycode(void) {
};
unsigned char buf[CONTROL_MSG_MAX_SIZE];
size_t size = control_msg_serialize(&msg, buf);
int size = control_msg_serialize(&msg, buf);
assert(size == 14);
const unsigned char expected[] = {
@ -39,7 +39,7 @@ static void test_serialize_inject_text(void) {
};
unsigned char buf[CONTROL_MSG_MAX_SIZE];
size_t size = control_msg_serialize(&msg, buf);
int size = control_msg_serialize(&msg, buf);
assert(size == 18);
const unsigned char expected[] = {
@ -59,7 +59,7 @@ static void test_serialize_inject_text_long(void) {
msg.inject_text.text = text;
unsigned char buf[CONTROL_MSG_MAX_SIZE];
size_t size = control_msg_serialize(&msg, buf);
int size = control_msg_serialize(&msg, buf);
assert(size == 5 + CONTROL_MSG_INJECT_TEXT_MAX_LENGTH);
unsigned char expected[5 + CONTROL_MSG_INJECT_TEXT_MAX_LENGTH];
@ -95,7 +95,7 @@ static void test_serialize_inject_touch_event(void) {
};
unsigned char buf[CONTROL_MSG_MAX_SIZE];
size_t size = control_msg_serialize(&msg, buf);
int size = control_msg_serialize(&msg, buf);
assert(size == 28);
const unsigned char expected[] = {
@ -130,7 +130,7 @@ static void test_serialize_inject_scroll_event(void) {
};
unsigned char buf[CONTROL_MSG_MAX_SIZE];
size_t size = control_msg_serialize(&msg, buf);
int size = control_msg_serialize(&msg, buf);
assert(size == 21);
const unsigned char expected[] = {
@ -149,7 +149,7 @@ static void test_serialize_back_or_screen_on(void) {
};
unsigned char buf[CONTROL_MSG_MAX_SIZE];
size_t size = control_msg_serialize(&msg, buf);
int size = control_msg_serialize(&msg, buf);
assert(size == 1);
const unsigned char expected[] = {
@ -164,7 +164,7 @@ static void test_serialize_expand_notification_panel(void) {
};
unsigned char buf[CONTROL_MSG_MAX_SIZE];
size_t size = control_msg_serialize(&msg, buf);
int size = control_msg_serialize(&msg, buf);
assert(size == 1);
const unsigned char expected[] = {
@ -179,7 +179,7 @@ static void test_serialize_collapse_notification_panel(void) {
};
unsigned char buf[CONTROL_MSG_MAX_SIZE];
size_t size = control_msg_serialize(&msg, buf);
int size = control_msg_serialize(&msg, buf);
assert(size == 1);
const unsigned char expected[] = {
@ -194,7 +194,7 @@ static void test_serialize_get_clipboard(void) {
};
unsigned char buf[CONTROL_MSG_MAX_SIZE];
size_t size = control_msg_serialize(&msg, buf);
int size = control_msg_serialize(&msg, buf);
assert(size == 1);
const unsigned char expected[] = {
@ -213,7 +213,7 @@ static void test_serialize_set_clipboard(void) {
};
unsigned char buf[CONTROL_MSG_MAX_SIZE];
size_t size = control_msg_serialize(&msg, buf);
int size = control_msg_serialize(&msg, buf);
assert(size == 19);
const unsigned char expected[] = {
@ -234,7 +234,7 @@ static void test_serialize_set_screen_power_mode(void) {
};
unsigned char buf[CONTROL_MSG_MAX_SIZE];
size_t size = control_msg_serialize(&msg, buf);
int size = control_msg_serialize(&msg, buf);
assert(size == 2);
const unsigned char expected[] = {
@ -250,7 +250,7 @@ static void test_serialize_rotate_device(void) {
};
unsigned char buf[CONTROL_MSG_MAX_SIZE];
size_t size = control_msg_serialize(&msg, buf);
int size = control_msg_serialize(&msg, buf);
assert(size == 1);
const unsigned char expected[] = {

View File

@ -4,6 +4,7 @@
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <SDL2/SDL.h>
#include "util/str_util.h"
@ -137,7 +138,7 @@ static void test_strquote(void) {
// add '"' at the beginning and the end
assert(!strcmp("\"abcde\"", out));
free(out);
SDL_free(out);
}
static void test_utf8_truncate(void) {