Skip to content
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

windows: address Visual Studio warnings #169

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions dtls_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,30 @@ static const char *loglevels[] = {

#ifdef HAVE_TIME_H

#ifndef IS_WINDOWS

static inline size_t
print_timestamp(char *s, size_t len, time_t t) {
struct tm *tmp;
tmp = localtime(&t);
return strftime(s, len, "%b %d %H:%M:%S", tmp);
}

#else

static inline size_t
print_timestamp(char *s, size_t len, time_t t) {
struct tm tmp;
errno_t err = localtime_s(&tmp, &t);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a that good practice, to use the OS instead of a specific HAVE_, if there is no good reason.

So, what is the warning here, you like to fix?

(Just, if you prefer, split the _CRT_RAND_S stuff in a second PR, that may be faster to merge.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your feedback on this, @boaks. I will shortly move the _CRT_RAND_S change to a separate PR.

Regarding the localtime change: IIRC, the warning it addresses is the following: C4996 'localtime': This function or variable may be unsafe. Consider using localtime_s instead

Do you have a suggestion how this could be solved in a better way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The _CRT_RAND_S change is now included separately in #178.

if (err) {
printf("Invalid argument to localtime_s.");
exit(1);
}
return strftime(s, len, "%b %d %H:%M:%S", &tmp);
}

#endif

#else /* alternative implementation: just print the timestamp */

static inline size_t
Expand Down