diff --git a/src/common/os.cpp b/src/common/os.cpp index 3822ad240..692ebbd0d 100644 --- a/src/common/os.cpp +++ b/src/common/os.cpp @@ -21,42 +21,41 @@ #include #include -int -vsscanf(const char *buffer, - const char *format, - va_list argPtr) { - // Get an upper bound for the # of args - size_t count = 0; - const char *p = format; - while (1) { - char c = *(p++); - if (c == 0) - break; - if ((c == '%') && ((p[0] != '*') && (p[0] != '%'))) - ++count; - } +int __declspec(naked) vsscanf_impl(const char *,const char *,va_list,int,void *) { + __asm { + push ebx + mov ebx,esp + mov ecx,[ebx+16] + mov edx,[ebx+20] + lea edx,[ecx+edx*4-4] + jmp l3 +l2: + push dword ptr [edx] + sub edx,4 +l3: + cmp edx,ecx + jae l2 + push dword ptr [ebx+12] + push dword ptr [ebx+8] + call dword ptr [ebx+24] + mov esp,ebx + pop ebx + ret + }; +} - // Make a local stack - size_t stackSize = (2 + count) * sizeof(void *); - void **newStack = (void **)alloca(stackSize); +int vsscanf(const char *str, const char *format, va_list ap) { + const char *p = format; + int narg = 0; - // Fill local stack the way sscanf likes it - newStack[0] = (void*)buffer; - newStack[1] = (void*)format; - memcpy(newStack + 2, argPtr, count * sizeof(void *)); + while (*p) + if (*p++ == '%') { + if (*p != '*' && *p != '%') + ++narg; + ++p; + } - // Warp into system sscanf with new stack - int result; - void *savedESP; - _asm { - mov savedESP, esp; - mov esp, newStack; - call sscanf; - mov esp, savedESP; - mov result, eax; - } - - return result; + return vsscanf_impl(str,format,ap,narg,sscanf); } #endif diff --git a/src/merge/mkvmerge.h b/src/merge/mkvmerge.h index 6e560fbbb..6978fd13f 100644 --- a/src/merge/mkvmerge.h +++ b/src/merge/mkvmerge.h @@ -26,7 +26,7 @@ enum display_priority_e { /* file types */ enum file_type_e { - FILE_TYPE_UNKNOWN = 0, + FILE_TYPE_IS_UNKNOWN = 0, FILE_TYPE_OGM, FILE_TYPE_AVI, FILE_TYPE_WAV, diff --git a/src/merge/output_control.cpp b/src/merge/output_control.cpp index 636b3c791..de98a9e3d 100644 --- a/src/merge/output_control.cpp +++ b/src/merge/output_control.cpp @@ -269,7 +269,7 @@ get_file_type(const string &filename) { filename.c_str()); } - type = FILE_TYPE_UNKNOWN; + type = FILE_TYPE_IS_UNKNOWN; if (avi_reader_c::probe_file(mm_io, size)) type = FILE_TYPE_AVI; else if (kax_reader_c::probe_file(mm_io, size)) @@ -324,7 +324,7 @@ get_file_type(const string &filename) { else if (vobsub_reader_c::probe_file(mm_text_io, size)) type = FILE_TYPE_VOBSUB; else - type = FILE_TYPE_UNKNOWN; + type = FILE_TYPE_IS_UNKNOWN; mm_io = mm_text_io; }