Skip to content

Use snprintf instead of _snprintf on Windows #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ _dispatch_ktrace_impl(uint32_t code, uint64_t a, uint64_t b,
dispatch_assert(_length != -1); \
_msg = (char *)malloc((unsigned)_length + 1); \
dispatch_assert(_msg); \
_snprintf(_msg, (unsigned)_length, "%s" fmt, DISPATCH_ASSERTION_FAILED_MESSAGE, ##__VA_ARGS__); \
snprintf(_msg, (unsigned)_length + 1, "%s" fmt, DISPATCH_ASSERTION_FAILED_MESSAGE, ##__VA_ARGS__); \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bleh; too bad that we still have the _scprintf here. Can we use snprintf with a 0 size instead to get the desired length? Then we could just use this version globally rather than having a windows only path. The difference between the asprintf version and this would be the extra calls, but it is on the abort path anyways, so I don't think that it matters too much.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree this is kinda nasty - is it fine if I make that change as a follow-up?

asprintf is also used in several places in test code :(

_dispatch_assert_crash(_msg); \
free(_msg); \
} while (0)
Expand Down
1 change: 0 additions & 1 deletion src/shims/generic_win_stubs.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ typedef __typeof__(_Generic((__SIZE_TYPE__)0, \
#define O_NONBLOCK 04000

#define bzero(ptr,len) memset((ptr), 0, (len))
#define snprintf _snprintf

#endif