diff --git a/json.cpp b/json.cpp index 571eaa9..521b5fe 100644 --- a/json.cpp +++ b/json.cpp @@ -92,7 +92,7 @@ const JSON &JSON::at(unsigned int index) const { int JSON::length() const { if( Type == Class::Array ) - return Internal.List->size(); + return static_cast(Internal.List->size()); else return -1; } @@ -105,9 +105,9 @@ bool JSON::hasKey(const std::string &key) const { int JSON::size() const { if( Type == Class::Object ) - return Internal.Map->size(); + return static_cast(Internal.Map->size()); else if( Type == Class::Array ) - return Internal.List->size(); + return static_cast(Internal.List->size()); else return -1; } diff --git a/lib/windows-x86_64/rktwebview.lib b/lib/windows-x86_64/rktwebview.lib new file mode 100644 index 0000000..94ee101 Binary files /dev/null and b/lib/windows-x86_64/rktwebview.lib differ diff --git a/main.cpp b/main.cpp index f6d0895..b20cd83 100644 --- a/main.cpp +++ b/main.cpp @@ -63,6 +63,7 @@ static void event_cb(rkt_data_t *data) free_data(data); } + int main(int argc, char *argv[]) { const char *me = argv[0]; diff --git a/rktwebview.cpp b/rktwebview.cpp index 6621dec..6abd1fa 100644 --- a/rktwebview.cpp +++ b/rktwebview.cpp @@ -31,6 +31,10 @@ #define ALIVE_SLOT 4 #define ALIVE_ACK_SLOT 5 +#ifdef _WIN32 +#define strdup _strdup +#endif + //#define DEBUG ///////////////////////////////////////////////////////////////////// @@ -106,12 +110,12 @@ bool runRktWebview(Handle_t *handler) char alive_slot[10]; char alive_ack_slot[10]; - sprintf(shm_size_str, "%d", static_cast(handler->shm_size)); - sprintf(command_slot, "%d", COMMAND_SLOT); - sprintf(command_result_slot, "%d", COMMAND_RESULT_SLOT); - sprintf(event_slot, "%d", EVENT_SLOT); - sprintf(alive_slot, "%d", ALIVE_SLOT); - sprintf(alive_ack_slot, "%d", ALIVE_ACK_SLOT); + snprintf(shm_size_str, 30, "%d", static_cast(handler->shm_size)); + snprintf(command_slot, 10, "%d", COMMAND_SLOT); + snprintf(command_result_slot, 10, "%d", COMMAND_RESULT_SLOT); + snprintf(event_slot, 10, "%d", EVENT_SLOT); + snprintf(alive_slot, 10, "%d", ALIVE_SLOT); + snprintf(alive_ack_slot, 10, "%d", ALIVE_ACK_SLOT); // run rktwebview_prg using the environment variable RKT_WEBVIEW_PRG @@ -316,7 +320,7 @@ void rkt_webview_init() #else #ifdef _WIN32 DWORD p = GetCurrentProcessId(); - sprintf(buf, "rktwebview-%ld", p); + snprintf(buf, 1024, "rktwebview-%ld", p); #else pid_t p = getpid(); sprintf(buf, "rktwebview-%x", p); diff --git a/shm.cpp b/shm.cpp index 9c8642e..cd9c280 100644 --- a/shm.cpp +++ b/shm.cpp @@ -138,7 +138,7 @@ public: first_i->prev = p_i; } i->prev = SHM_NULL; - i->alloc_size = bytes; + i->alloc_size = static_cast(bytes); *_first = p_i; place = p_i + sizeof(ShmItem); @@ -152,8 +152,8 @@ public: } else { *_used = u; i->prev = SHM_NULL; - i->size = bytes; - i->alloc_size = bytes; + i->size = static_cast(bytes); + i->alloc_size = static_cast(bytes); i->next = *_first; if (*_first != SHM_NULL) { ShmItem *first_i; @@ -180,6 +180,7 @@ public: ShmPlace p_i = place - sizeof(ShmItem); ShmItem *i; ref(p_i, &i); + if (i == nullptr) return; if (i->prev != SHM_NULL) { ShmItem *prev_i; @@ -218,8 +219,9 @@ public: public: ShmApiBase(const char *name, size_t size, bool owner) { - char *buf = reinterpret_cast(malloc(strlen(name) + 50)); - sprintf(buf, "sem_%s", name); + size_t buf_size = strlen(name) + 50; + char *buf = reinterpret_cast(malloc(buf_size)); + snprintf(buf, buf_size, "sem_%s", name); _sem_name = _strdup(buf); _mem_name = _strdup(name); ::free(buf); @@ -495,7 +497,7 @@ public: if (_owner) { *_first = SHM_NULL; *_free_list = SHM_NULL; - *_used = sizeof(int) + sizeof(ShmItem *) + sizeof(ShmItem *) + slots_size; + *_used = static_cast(sizeof(int) + sizeof(ShmItem *) + sizeof(ShmItem *) + slots_size); } } } diff --git a/shmqueue.cpp b/shmqueue.cpp index 514d418..d5ed712 100644 --- a/shmqueue.cpp +++ b/shmqueue.cpp @@ -1,6 +1,10 @@ #include "shmqueue.h" #include +#ifdef _WIN32 +#define sprintf sprintf_s +#endif + ShmQueue::ShmQueue(Shm *shm, ShmSlot slot, bool owner) { _shm = shm;