From fc4c242442510fb97c3cfbf04d7582ebbc3bb0ed Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 24 Apr 2024 15:51:43 -0700 Subject: Fix macos CI and clang warnings. (#4019) * Fix macos CI. * Fix. * Fix. * Fix. * Fix clang warnings. * Fix more warnings. --- source/slang/slang-emit-source-writer.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'source/slang/slang-emit-source-writer.cpp') diff --git a/source/slang/slang-emit-source-writer.cpp b/source/slang/slang-emit-source-writer.cpp index d8364d5c3..ddce0ab89 100644 --- a/source/slang/slang-emit-source-writer.cpp +++ b/source/slang/slang-emit-source-writer.cpp @@ -3,10 +3,6 @@ #include "../core/slang-char-encode.h" -// Disable warnings about sprintf -#ifdef _WIN32 -# pragma warning(disable:4996) -#endif // Note: using C++ stdio just to get a locale-independent // way to format floating-point values. @@ -199,28 +195,28 @@ void SourceWriter::emitInt64(int64_t value) void SourceWriter::emit(Int32 value) { char buffer[16]; - sprintf(buffer, "%" PRId32, value); + snprintf(buffer, sizeof(buffer), "%" PRId32, value); emit(buffer); } void SourceWriter::emit(Int64 value) { char buffer[32]; - sprintf(buffer, "%" PRId64, value); + snprintf(buffer, sizeof(buffer), "%" PRId64, value); emit(buffer); } void SourceWriter::emit(UInt32 value) { char buffer[32]; - sprintf(buffer, "%" PRIu32, value); + snprintf(buffer, sizeof(buffer), "%" PRIu32, value); emit(buffer); } void SourceWriter::emit(UInt64 value) { char buffer[32]; - sprintf(buffer, "%" PRIu64, value); + snprintf(buffer, sizeof(buffer), "%" PRIu64, value); emit(buffer); } @@ -463,7 +459,7 @@ void SourceWriter::_emitLineDirective(const HumaneSourceLoc& sourceLocation) emitRawText("\n#line "); char buffer[16]; - sprintf(buffer, "%llu", (unsigned long long)sourceLocation.line); + snprintf(buffer, sizeof(buffer), "%llu", (unsigned long long)sourceLocation.line); emitRawText(buffer); // Only emit the path part of a `#line` directive if needed @@ -497,7 +493,7 @@ void SourceWriter::_emitLineDirective(const HumaneSourceLoc& sourceLocation) m_mapGLSLSourcePathToID.add(path, id); } - sprintf(buffer, "%d", id); + snprintf(buffer, sizeof(buffer), "%d", id); emitRawText(buffer); break; } -- cgit v1.2.3