#Find possible win32 error codes like in stdlib?

1 messages · Page 1 of 1 (latest)

burnt sparrow
#

Trying to simulate bad behaviour by passing undefined to some zig functions which in turn call some C functions, they error as expected unless in Debug mode because 0xaa is considered valid input.

Can I disable that behaviour temporarily or are there any decent workarounds apart from using ReleaseSafe ?

oblique prawn
#

including 0xaa

#

its value is undefined

#

eg in practice its whatever value was in that memory location before

#

there is no way to detect use of undefined in release modes by definition, dont try

burnt sparrow
#

I thought undefined / uninitialized memory meant that it had "nothing" or pointed to a non existing location or smth but 2 seconds of Wikipedia says otherwise zeroClueless

#

Is there a better way to do what I was trying to do than passing undefined then?

#

Trying to see what behavior / errors I can get from a C function with invalid arguments

oblique prawn
#

read the docs

#

or the code

burnt sparrow
#

It's Win32 API
Their docs basically say something like: "it has too many changing variables depending on the machine, we can't document all the errors this thing returns"

oblique prawn
#

then iterate over every possible input or something idk

dull plover
#

what's the function?

burnt sparrow
burnt sparrow
# burnt sparrow It's Win32 API Their docs basically say something like: "it has too many changin...

https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror#remarks

The error codes returned by a function are not part of the Windows API specification and can vary by operating system or device driver. For this reason, we cannot provide the complete list of error codes that can be returned by each function. There are also many functions whose documentation does not include even a partial list of error codes that can be returned.

#

I looked at stdlib before and this's all I found:
https://github.com/ziglang/zig/blob/master/lib%2Fstd%2Fos.zig#L5670-L5673

/// Whether or not error.Unexpected will print its value and a stack trace.
/// if this happens the fix is to add the error code to the corresponding
/// switch expression, possibly introduce a new error in the error set, and
/// send a patch to Zig. 
#

Find possible win32 error codes like in stdlib?

dull plover
burnt sparrow
#

That I do know, it has an enum in std.os.windows.Win32Error as well

#

It's more about "which ones does X function return?"

dull plover
#

pretty sure that'd be an implementation detail on microsoft's side

burnt sparrow
#

yeah seems so, yet stdlib seems to have a grip on them somehow

#

I would assume a good chunk of this might come from looking at wine source code, but wine doesn't port all functions

dull plover
#

from the git history, looks like they were added one by one in reaction to the errors occurring in the wild

burnt sparrow
#

guess so ¯_(ツ)_/¯

#

I'll prolly do the same then

#

Passing undefined seemed to give at least some info tho, should I just keep doing that to at least get what I can or could it be bad for some reason?

dull plover
#

it's virtually the equivalent of passing a random number from a very bad rng

#

if you need to know all the possible unexpected errors to display relevant messages to the user, you'd be better of using FormatMessage rather than rolling your own

#

otherwise "did it work?" "yes/no(unknown)/no(handled)" is likely enough at runtime, and when debugging the unknown error codes can always be looked up

burnt sparrow
#

Yeah fair enough

#

I was more just curious about how much I can turn into specific zig errors like in stdlib

#

But I figure it's not really gonna have much benefit if I never face them and just spam undefined lol