From 3d12246b1405836583d59ef75568f8c5d51b69e4 Mon Sep 17 00:00:00 2001 From: Sylvain Lefebvre Date: Thu, 24 Aug 2023 11:00:30 +0000 Subject: [PATCH] fixes to error reporting string formats (#255) --- CMakeLists.txt | 5 +++++ src/Algorithm.cpp | 4 ++-- src/LuaPreProcessor.cpp | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 308354cd..427dc664 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,6 +142,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND message(FATAL_ERROR "Silice requires g++ 8 at least") endif() +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=format -Werror=format-security") +endif() + + set(STD_FS_LIB "") # ==== The test below is based on https://github.com/pybind/pybind11/blob/master/tests/CMakeLists.txt # It is under a BSD-style license, see https://github.com/pybind/pybind11/blob/master/LICENSE diff --git a/src/Algorithm.cpp b/src/Algorithm.cpp index 3dc3b1b4..132162f6 100644 --- a/src/Algorithm.cpp +++ b/src/Algorithm.cpp @@ -6295,7 +6295,7 @@ void Algorithm::checkExpressions(const t_instantiation_context &ictx,antlr4::tre if (A != m_InstancedBlueprints.end()) { // algorithm? Algorithm *alg = dynamic_cast(A->second.blueprint.raw()); if (alg == nullptr) { - reportError(sourceloc(async), "called instance '%s' is not an algorithm", async->IDENTIFIER()->getText().c_str()); + reportError(sourceloc(sync), "called instance '%s' is not an algorithm", sync->joinExec()->IDENTIFIER()->getText().c_str()); } else { // if parameters are given, check, otherwise we allow call without parameters (bindings may exist) if (!sync->callParamList()->expression_0().empty()) { @@ -6333,7 +6333,7 @@ void Algorithm::checkExpressions(const t_instantiation_context &ictx,antlr4::tre if (A != m_InstancedBlueprints.end()) { // algorithm? Algorithm *alg = dynamic_cast(A->second.blueprint.raw()); if (alg == nullptr) { - reportError(sourceloc(async), "joined instance '%s' is not an algorithm", async->IDENTIFIER()->getText().c_str()); + reportError(sourceloc(join), "joined instance '%s' is not an algorithm", join->IDENTIFIER()->getText().c_str()); } else { // if parameters are given, check, otherwise we allow call without parameters (bindings may exist) if (!join->callParamList()->expression_0().empty()) { diff --git a/src/LuaPreProcessor.cpp b/src/LuaPreProcessor.cpp index db26bbed..a573f0d3 100644 --- a/src/LuaPreProcessor.cpp +++ b/src/LuaPreProcessor.cpp @@ -1055,7 +1055,7 @@ void LuaPreProcessor::decomposeSource( if (w == "unit" || w == "algorithm" || w == "algorithm#" || w == "circuitry") { std::string name = parser.readString("( \t\r"); if (name.empty()) { - throw Fatal((w + " has no name").c_str()); // TODO: improve error report (line) + throw Fatal("%s",(w + " has no name").c_str()); // TODO: improve error report (line) } cerr << "functionalizing " << w << ' ' << name << '\n'; if (w == "algorithm#") {