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

Contam throws Wdeprecated-declarations for use of sprintf on modern clang #4737

Closed
jmarrec opened this issue Nov 4, 2022 · 0 comments · Fixed by #4902
Closed

Contam throws Wdeprecated-declarations for use of sprintf on modern clang #4737

jmarrec opened this issue Nov 4, 2022 · 0 comments · Fixed by #4902

Comments

@jmarrec
Copy link
Collaborator

jmarrec commented Nov 4, 2022

Issue overview

Modernize C-like code in contam:

try {
char buffer[256];
openstudio::Date start(rp->getBeginMonth(), rp->getBeginDayOfMonth());
sprintf(buffer, "%02d", start.dayOfMonth());
startString = start.monthOfYear().valueName() + std::string(buffer);
openstudio::Date end(rp->getEndMonth(), rp->getEndDayOfMonth());
sprintf(buffer, "%02d", end.dayOfMonth());
endString = end.monthOfYear().valueName() + std::string(buffer);
m_startDateTime = boost::optional<DateTime>(DateTime(start, Time(0)));
m_endDateTime = boost::optional<DateTime>(DateTime(end, Time(0, 24)));
} catch (...) {
goodDates = false;
LOG(Error, "Failed to get usable start of end date from run period object, defaulting to steady state")
}

Current Behavior

OpenStudio/src/airflow/contam/ForwardTranslator.cpp:90:5: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations]
    sprintf(buffer, "%02d/%02d\t%02d:%02d:%02d", month(datetime.date().monthOfYear()), datetime.date().dayOfMonth(), datetime.time().hours(),
    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here
__deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
^

Expected Behavior

Build shouldn't fail.

Steps to Reproduce

Macos Monterey 12.6 (21G115), M1

Apple clang version 14.0.0 (clang-1400.0.29.102)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Possible Solution

Replace buffer / sprintf with modern C++ (eg : fmt::format)

@jmarrec jmarrec added Triage Issue needs to be assessed and labeled, further information on reported might be needed severity - Normal Bug Developer Issue and removed Triage Issue needs to be assessed and labeled, further information on reported might be needed labels Nov 4, 2022
jmarrec added a commit that referenced this issue Nov 4, 2022
tijcolem added a commit that referenced this issue Jun 20, 2023
Fix #4737 - Replace sprintf usage with fmt::format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant