diff --git a/build/dehydra/printf-type-check.js b/build/dehydra/printf-type-check.js index 7176e30dad..b519145095 100644 --- a/build/dehydra/printf-type-check.js +++ b/build/dehydra/printf-type-check.js @@ -67,11 +67,25 @@ function find_printf_type(decl, loc) { return ['w', 'printf', 2, 3]; else if (name == 'swprintf') return ['w', 'printf', 3, 4]; - else if (name == 'JS_ReportError') + + // SpiderMonkey: + if (name == 'JS_ReportError') return ['a', 'printf', 2, 3]; else if (name == 'JS_ReportWarning') return ['a', 'printf', 2, 3]; + // Mongoose: + if (name == 'mg_printf') + return ['a', 'printf', 2, 3]; + else if (name == 'mg_snprintf') + return ['a', 'printf', 4, 5]; + else if (name == 'send_http_error') + return ['a', 'printf', 4, 5]; + else if (name == 'cry') + return ['a', 'printf', 2, 3]; + else if (name == 'mg_md5') + return; + // Ignore vararg functions that we know aren't using normal format strings if (name.match(/^(__builtin_va_start|execlp|open|fcntl|ioctl|sem_open|h_alloc|sys_wopen|ogl_HaveExtensions|JS_ConvertArguments|curl_easy_setopt|curl_easy_getinfo|SMBIOS::FieldInitializer::Read|SMBIOS::FieldStringizer::Write)$/)) return; @@ -139,6 +153,8 @@ function compare_format_type(ctype, functype, fmt, arg, loc) { return (arg == 'float*'); if (t.match(/^l[aefg]$/)) return (arg == 'double*'); + if (t.match(/^n$/)) + return (arg == 'int*'); // ... } @@ -160,10 +176,16 @@ function check_arg_types(ctype, functype, fmt_string, arg_type_names, loc) { if (fmt_type != '%%') ++num_fmt_types; - // Each '*' eats an extra argument - var stars = fmt_type.match(/\*/g); - if (stars) - num_fmt_types += stars.length; + if (functype == 'printf') { + // In printf, each '*' eats an extra argument + var stars = fmt_type.match(/\*/g); + if (stars) + num_fmt_types += stars.length; + } else if (functype == 'scanf') { + // In scanf, a '*' prefix means the argument is omitted + if (fmt_type.match(/^%\*/)) + --num_fmt_types; + } } if (num_fmt_types != arg_type_names.length) { @@ -173,15 +195,21 @@ function check_arg_types(ctype, functype, fmt_string, arg_type_names, loc) { for each (var fmt_type in fmt_types) { if (fmt_type != '%%') { - // Each '*' eats an extra argument of type int - var stars = fmt_type.match(/\*/g); - if (stars) { - for (var s in stars) { - var arg = arg_type_names.shift(); - if (! compare_format_type(ctype, functype, '%d', arg, loc)) { - error('Invalid argument type "'+arg+'" for format specifier "'+fmt_type+'"', loc()); + if (functype == 'printf') { + // In printf, each '*' eats an extra argument of type int + var stars = fmt_type.match(/\*/g); + if (stars) { + for (var s in stars) { + var arg = arg_type_names.shift(); + if (! compare_format_type(ctype, functype, '%d', arg, loc)) { + error('Invalid argument type "'+arg+'" for format specifier "'+fmt_type+'"', loc()); + } } } + } else if (functype == 'scanf') { + // In scanf, a '*' prefix means the argument is omitted + if (fmt_type.match(/^%\*/)) + continue; } var arg = arg_type_names.shift(); @@ -190,6 +218,10 @@ function check_arg_types(ctype, functype, fmt_string, arg_type_names, loc) { } } } + + if (arg_type_names.length) { + error('Internal error: got some arg types left over'); + } } function type_string_without_typedefs(type) { diff --git a/source/lib/allocators/dynarray.cpp b/source/lib/allocators/dynarray.cpp index ec8fe9c365..a8b80ead05 100644 --- a/source/lib/allocators/dynarray.cpp +++ b/source/lib/allocators/dynarray.cpp @@ -112,7 +112,7 @@ Status da_set_size(DynArray* da, size_t new_size) { ok = vm::Commit(uintptr_t(end), size_delta_pa); if(!ok) - debug_printf(L"Commit failed (%p %d)\n", end, size_delta_pa); + debug_printf(L"Commit failed (%p %lld)\n", end, (long long)size_delta_pa); } // shrinking else if(size_delta_pa < 0) diff --git a/source/lib/debug.cpp b/source/lib/debug.cpp index 36e8e17060..5d5f821fd1 100644 --- a/source/lib/debug.cpp +++ b/source/lib/debug.cpp @@ -541,7 +541,7 @@ ErrorReaction debug_OnError(Status err, atomic_bool* suppress, const wchar_t* fi const wchar_t* lastFuncToSkip = L"debug_OnError"; wchar_t buf[400]; wchar_t err_buf[200]; StatusDescription(err, err_buf, ARRAY_SIZE(err_buf)); - swprintf_s(buf, ARRAY_SIZE(buf), L"Function call failed: return value was %lld (%ls)", err, err_buf); + swprintf_s(buf, ARRAY_SIZE(buf), L"Function call failed: return value was %lld (%ls)", (long long)err, err_buf); return debug_DisplayError(buf, DE_MANUAL_BREAK, context, lastFuncToSkip, file,line,func, suppress); } diff --git a/source/lib/res/h_mgr.cpp b/source/lib/res/h_mgr.cpp index 61314d6da4..bc98930308 100644 --- a/source/lib/res/h_mgr.cpp +++ b/source/lib/res/h_mgr.cpp @@ -258,7 +258,7 @@ static Status h_data_tag_type(const Handle h, const H_Type type, HDATA*& hd) // h_alloc makes sure type isn't 0, so no need to check that here. if(hd->type != type) { - debug_printf(L"h_mgr: expected type %ws, got %ws\n", hd->type->name, type->name); + debug_printf(L"h_mgr: expected type %ls, got %ls\n", hd->type->name, type->name); WARN_RETURN(ERR::H_TYPE_MISMATCH); } diff --git a/source/lib/status.cpp b/source/lib/status.cpp index 66a68d95a2..1fe1cb063e 100644 --- a/source/lib/status.cpp +++ b/source/lib/status.cpp @@ -85,7 +85,7 @@ wchar_t* StatusDescription(Status status, wchar_t* buf, size_t max_chars) return buf; } - swprintf_s(buf, max_chars, L"Unknown error (%lld, 0x%llX)", status, status); + swprintf_s(buf, max_chars, L"Unknown error (%lld, 0x%llX)", (long long)status, (long long)status); return buf; } diff --git a/source/network/NetFileTransfer.cpp b/source/network/NetFileTransfer.cpp index 200cd1bd93..02805e3358 100644 --- a/source/network/NetFileTransfer.cpp +++ b/source/network/NetFileTransfer.cpp @@ -30,7 +30,7 @@ Status CNetFileTransferer::HandleMessageReceive(const CNetMessage* message) task->m_Length = respMessage->m_Length; task->m_Buffer.reserve(respMessage->m_Length); - LOGMESSAGERENDER(L"Downloading data over network (%d KB) - please wait...", task->m_Length/1024); + LOGMESSAGERENDER(L"Downloading data over network (%d KB) - please wait...", (int)(task->m_Length/1024)); m_LastProgressReportTime = timer_Time(); return INFO::OK; @@ -75,7 +75,7 @@ Status CNetFileTransferer::HandleMessageReceive(const CNetMessage* message) double t = timer_Time(); if (t > m_LastProgressReportTime + 0.5) { - LOGMESSAGERENDER(L"Downloading data: %.1f%% of %d KB", 100.f*task->m_Buffer.size()/task->m_Length, task->m_Length/1024); + LOGMESSAGERENDER(L"Downloading data: %.1f%% of %d KB", 100.f*task->m_Buffer.size()/task->m_Length, (int)(task->m_Length/1024)); m_LastProgressReportTime = t; } @@ -156,4 +156,4 @@ void CNetFileTransferer::Poll() } // TODO: need to garbage-collect finished tasks -} \ No newline at end of file +} diff --git a/source/ps/ConfigDB.cpp b/source/ps/ConfigDB.cpp index 6f4e229b99..ad68836d02 100644 --- a/source/ps/ConfigDB.cpp +++ b/source/ps/ConfigDB.cpp @@ -351,7 +351,7 @@ bool CConfigDB::Reload(EConfigNamespace ns) Status ret = g_VFS->LoadFile(m_ConfigFile[ns], buffer, buflen); if (ret != INFO::OK) { - LOGERROR(L"CConfigDB::Reload(): vfs_load for \"%ls\" failed: return was %lld", m_ConfigFile[ns].string().c_str(), ret); + LOGERROR(L"CConfigDB::Reload(): vfs_load for \"%ls\" failed: return was %lld", m_ConfigFile[ns].string().c_str(), (long long)ret); return false; } } diff --git a/source/ps/Filesystem.cpp b/source/ps/Filesystem.cpp index 60a9ca01f7..859c59f671 100644 --- a/source/ps/Filesystem.cpp +++ b/source/ps/Filesystem.cpp @@ -114,7 +114,7 @@ PSRETURN CVFSFile::Load(const PIVFS& vfs, const VfsPath& filename) Status ret = vfs->LoadFile(filename, m_Buffer, m_BufferSize); if (ret != INFO::OK) { - LOGERROR(L"CVFSFile: file %ls couldn't be opened (vfs_load: %lld)", filename.string().c_str(), ret); + LOGERROR(L"CVFSFile: file %ls couldn't be opened (vfs_load: %lld)", filename.string().c_str(), (long long)ret); return PSRETURN_CVFSFile_LoadFailed; } diff --git a/source/ps/Profiler2.cpp b/source/ps/Profiler2.cpp index 93486ecaa0..3935e654ba 100644 --- a/source/ps/Profiler2.cpp +++ b/source/ps/Profiler2.cpp @@ -107,7 +107,7 @@ static void* MgCallback(mg_event event, struct mg_connection *conn, const struct } else { - mg_printf(conn, header404); + mg_printf(conn, "%s", header404); return handled; } diff --git a/source/ps/Profiler2.h b/source/ps/Profiler2.h index c058d87df4..3508a10f50 100644 --- a/source/ps/Profiler2.h +++ b/source/ps/Profiler2.h @@ -161,9 +161,9 @@ private: Record(ITEM_EVENT, t, "__framestart"); // magic string recognised by the visualiser } - void RecordAttribute(const char* fmt, va_list argp); + void RecordAttribute(const char* fmt, va_list argp) VPRINTF_ARGS(2); - void RecordAttributePrintf(const char* fmt, ...) + void RecordAttributePrintf(const char* fmt, ...) PRINTF_ARGS(2) { va_list argp; va_start(argp, fmt); @@ -321,7 +321,7 @@ public: GetThreadStorage().Record(ITEM_LEAVE, GetTime(), id); } - void RecordAttribute(const char* fmt, ...) + void RecordAttribute(const char* fmt, ...) PRINTF_ARGS(2) { va_list argp; va_start(argp, fmt); diff --git a/source/ps/Profiler2GPU.cpp b/source/ps/Profiler2GPU.cpp index 74ddac9bcc..2eec1ef346 100644 --- a/source/ps/Profiler2GPU.cpp +++ b/source/ps/Profiler2GPU.cpp @@ -639,7 +639,7 @@ private: ogl_WarnIfError(); ENSURE(length == m_QueryTypes[j].counterBufferSize); - m_Storage.RecordAttributePrintf("-- %hs --", m_QueryTypes[j].name.c_str()); + m_Storage.RecordAttributePrintf("-- %s --", m_QueryTypes[j].name.c_str()); for (size_t k = 0; k < m_QueryTypes[j].counters.size(); ++k) { @@ -650,14 +650,14 @@ private: ENSURE(counter.size == 4); GLuint value; memcpy(&value, buf + counter.offset, counter.size); - m_Storage.RecordAttributePrintf("%hs: %d", counter.name.c_str(), value); + m_Storage.RecordAttributePrintf("%s: %d", counter.name.c_str(), value); } else if (counter.type == INTEL_PERFQUERIES_TYPE_UNSIGNED_INT64) { ENSURE(counter.size == 8); GLuint64 value; memcpy(&value, buf + counter.offset, counter.size); - m_Storage.RecordAttributePrintf("%hs: %.0f", counter.name.c_str(), (double)value); + m_Storage.RecordAttributePrintf("%s: %.0f", counter.name.c_str(), (double)value); if (counter.name == "TotalTime") elapsed = (double)value / 1e6; @@ -667,7 +667,7 @@ private: ENSURE(counter.size == 4); GLfloat value; memcpy(&value, buf + counter.offset, counter.size); - m_Storage.RecordAttributePrintf("%hs: %f", counter.name.c_str(), value); + m_Storage.RecordAttributePrintf("%s: %f", counter.name.c_str(), value); } else if (counter.type == INTEL_PERFQUERIES_TYPE_BOOL) { @@ -675,7 +675,7 @@ private: GLuint value; memcpy(&value, buf + counter.offset, counter.size); ENSURE(value == 0 || value == 1); - m_Storage.RecordAttributePrintf("%hs: %d", counter.name.c_str(), value); + m_Storage.RecordAttributePrintf("%s: %d", counter.name.c_str(), value); } else { diff --git a/source/ps/XML/XMLWriter.cpp b/source/ps/XML/XMLWriter.cpp index 2111aa017c..1a8dd80af1 100644 --- a/source/ps/XML/XMLWriter.cpp +++ b/source/ps/XML/XMLWriter.cpp @@ -102,7 +102,7 @@ bool XMLWriter_File::StoreVFS(const PIVFS& vfs, const VfsPath& pathname) Status ret = vfs->CreateFile(pathname, data, size); if (ret < 0) { - LOGERROR(L"Error saving XML data through VFS: %lld", ret); + LOGERROR(L"Error saving XML data through VFS: %lld", (long long)ret); return false; } return true; diff --git a/source/renderer/VertexBuffer.cpp b/source/renderer/VertexBuffer.cpp index 204d55baa8..bcbfebe42f 100644 --- a/source/renderer/VertexBuffer.cpp +++ b/source/renderer/VertexBuffer.cpp @@ -234,14 +234,14 @@ size_t CVertexBuffer::GetBytesAllocated() const void CVertexBuffer::DumpStatus() { - debug_printf(L"freeverts = %d\n", m_FreeVertices); + debug_printf(L"freeverts = %d\n", (int)m_FreeVertices); size_t maxSize = 0; typedef std::list::iterator Iter; for (Iter iter = m_FreeList.begin(); iter != m_FreeList.end(); ++iter) { - debug_printf(L"free chunk %p: size=%d\n", *iter, (*iter)->m_Count); + debug_printf(L"free chunk %p: size=%d\n", *iter, (int)((*iter)->m_Count)); maxSize = std::max((*iter)->m_Count, maxSize); } - debug_printf(L"max size = %d\n", maxSize); + debug_printf(L"max size = %d\n", (int)maxSize); } diff --git a/source/simulation2/components/CCmpRangeManager.cpp b/source/simulation2/components/CCmpRangeManager.cpp index 68dff4613a..0a7c172f64 100644 --- a/source/simulation2/components/CCmpRangeManager.cpp +++ b/source/simulation2/components/CCmpRangeManager.cpp @@ -452,14 +452,14 @@ public: { for (size_t i = 0; i < oldPlayerCounts.size(); ++i) { - debug_printf(L"%d: ", i); + debug_printf(L"%d: ", (int)i); for (size_t j = 0; j < oldPlayerCounts[i].size(); ++j) debug_printf(L"%d ", oldPlayerCounts[i][j]); debug_printf(L"\n"); } for (size_t i = 0; i < m_LosPlayerCounts.size(); ++i) { - debug_printf(L"%d: ", i); + debug_printf(L"%d: ", (int)i); for (size_t j = 0; j < m_LosPlayerCounts[i].size(); ++j) debug_printf(L"%d ", m_LosPlayerCounts[i][j]); debug_printf(L"\n"); diff --git a/source/third_party/mongoose/mongoose.cpp b/source/third_party/mongoose/mongoose.cpp index 8ac9e8f56c..06782b11c0 100644 --- a/source/third_party/mongoose/mongoose.cpp +++ b/source/third_party/mongoose/mongoose.cpp @@ -1590,7 +1590,7 @@ static void convert_uri_to_file_name(struct mg_connection *conn, int match_len; match_len = get_document_root(conn, &vec); - mg_snprintf(conn, buf, buf_len, "%.*s%s", vec.len, vec.ptr, uri + match_len); + mg_snprintf(conn, buf, buf_len, "%.*s%s", (int) vec.len, vec.ptr, uri + match_len); #if defined(_WIN32) && !defined(__SYMBIAN32__) change_slashes_to_backslashes(buf); @@ -2203,7 +2203,7 @@ static int check_authorization(struct mg_connection *conn, const char *path) { while ((list = next_option(list, &uri_vec, &filename_vec)) != NULL) { if (!memcmp(conn->request_info.uri, uri_vec.ptr, uri_vec.len)) { (void) mg_snprintf(conn, fname, sizeof(fname), "%.*s", - filename_vec.len, filename_vec.ptr); + (int) filename_vec.len, filename_vec.ptr); if ((fp = mg_fopen(fname, "r")) == NULL) { cry(conn, "%s: cannot open %s: %s", __func__, fname, strerror(errno)); } @@ -2599,7 +2599,7 @@ static void handle_file_request(struct mg_connection *conn, const char *path, "Accept-Ranges: bytes\r\n" "%s\r\n", conn->request_info.status_code, msg, date, lm, etag, - mime_vec.len, mime_vec.ptr, cl, suggest_connection_header(conn), range); + (int) mime_vec.len, mime_vec.ptr, cl, suggest_connection_header(conn), range); if (strcmp(conn->request_info.request_method, "HEAD") != 0) { send_file_data(conn, fp, cl); @@ -3139,7 +3139,7 @@ static void do_ssi_include(struct mg_connection *conn, const char *ssi, if (sscanf(tag, " virtual=\"%[^\"]\"", file_name) == 1) { // File name is relative to the webserver root (void) mg_snprintf(conn, path, sizeof(path), "%.*s%c%s", - root.len, root.ptr, DIRSEP, file_name); + (int) root.len, root.ptr, DIRSEP, file_name); } else if (sscanf(tag, " file=\"%[^\"]\"", file_name) == 1) { // File name is relative to the webserver working directory // or it is absolute system path @@ -3467,7 +3467,7 @@ static int set_ports_option(struct mg_context *ctx) { while (success && (list = next_option(list, &vec, NULL)) != NULL) { if (!parse_port_string(&vec, &so)) { cry(fc(ctx), "%s: %.*s: invalid port spec. Expecting list of: %s", - __func__, vec.len, vec.ptr, "[IP_ADDRESS:]PORT[s|p]"); + __func__, (int) vec.len, vec.ptr, "[IP_ADDRESS:]PORT[s|p]"); success = 0; } else if (so.is_ssl && ctx->ssl_ctx == NULL) { cry(fc(ctx), "Cannot add SSL socket, is -ssl_certificate option set?"); @@ -3492,7 +3492,7 @@ static int set_ports_option(struct mg_context *ctx) { listen(sock, 100) != 0) { closesocket(sock); cry(fc(ctx), "%s: cannot bind to %.*s: %s", __func__, - vec.len, vec.ptr, strerror(ERRNO)); + (int) vec.len, vec.ptr, strerror(ERRNO)); success = 0; } else if ((listener = (struct socket *) calloc(1, sizeof(*listener))) == NULL) {