diff --git a/dlls/ntdll/exception.c b/dlls/ntdll/exception.c index 59177b77c79..8286c9dcd52 100644 --- a/dlls/ntdll/exception.c +++ b/dlls/ntdll/exception.c @@ -346,3 +346,47 @@ void __wine_spec_unimplemented_stub( const char *module, const char *function ) record.ExceptionInformation[1] = (ULONG_PTR)function; for (;;) RtlRaiseException( &record ); } + + +/************************************************************* + * IsBadStringPtrA + * + * IsBadStringPtrA replacement for ntdll, to catch exception in debug traces. + */ +BOOL WINAPI IsBadStringPtrA( LPCSTR str, UINT_PTR max ) +{ + if (!str) return TRUE; + __TRY + { + volatile const char *p = str; + while (p != str + max) if (!*p++) break; + } + __EXCEPT_PAGE_FAULT + { + return TRUE; + } + __ENDTRY + return FALSE; +} + + +/************************************************************* + * IsBadStringPtrW + * + * IsBadStringPtrW replacement for ntdll, to catch exception in debug traces. + */ +BOOL WINAPI IsBadStringPtrW( LPCWSTR str, UINT_PTR max ) +{ + if (!str) return TRUE; + __TRY + { + volatile const WCHAR *p = str; + while (p != str + max) if (!*p++) break; + } + __EXCEPT_PAGE_FAULT + { + return TRUE; + } + __ENDTRY + return FALSE; +} diff --git a/include/wine/debug.h b/include/wine/debug.h index c7eb185257f..bb728270593 100644 --- a/include/wine/debug.h +++ b/include/wine/debug.h @@ -24,9 +24,7 @@ #include #include #include -#ifndef _NTSYSTEM_ #include -#endif #ifndef GUID_DEFINED #include #endif @@ -227,9 +225,7 @@ static inline const char *wine_dbgstr_an( const char *str, int n ) if (!str) return "(null)"; if (!((ULONG_PTR)str >> 16)) return wine_dbg_sprintf( "#%04x", LOWORD(str) ); -#ifndef _NTSYSTEM_ if (IsBadStringPtrA( str, n )) return "(invalid)"; -#endif if (n == -1) for (n = 0; str[n]; n++) ; *dst++ = '"'; while (n-- > 0 && dst <= buffer + sizeof(buffer) - 9) @@ -271,9 +267,7 @@ static inline const char *wine_dbgstr_wn( const WCHAR *str, int n ) if (!str) return "(null)"; if (!((ULONG_PTR)str >> 16)) return wine_dbg_sprintf( "#%04x", LOWORD(str) ); -#ifndef _NTSYSTEM_ if (IsBadStringPtrW( str, n )) return "(invalid)"; -#endif if (n == -1) for (n = 0; str[n]; n++) ; *dst++ = 'L'; *dst++ = '"';