Sfoglia il codice sorgente

Add printf-style warnings to the Log system. Fix resulting warnings.

Michael Ragazzon 4 anni fa
parent
commit
0639b0fff0

+ 2 - 2
Include/RmlUi/Core/Log.h

@@ -64,13 +64,13 @@ public:
 	/// Log the specified message via the registered log interface
 	/// @param[in] type Type of message.
 	/// @param[in] format The message, with sprintf-style parameters.
-	static void Message(Type type, const char* format, ...);
+	static void Message(Type type, const char* format, ...) RMLUI_ATTRIBUTE_FORMAT_PRINTF(2, 3);
 
 	/// Log a parse error on the specified file and line number.
 	/// @param[in] filename Name of the file with the parse error.
 	/// @param[in] line_number Line the error occured on.
 	/// @param[in] format The error message, with sprintf-style parameters.
-	static void ParseError(const String& filename, int line_number, const char* format, ...);
+	static void ParseError(const String& filename, int line_number, const char* format, ...) RMLUI_ATTRIBUTE_FORMAT_PRINTF(3, 4);
 };
 
 } // namespace Rml

+ 6 - 6
Source/Core/DataExpression.cpp

@@ -143,12 +143,12 @@ public:
 	void Error(const String message)
 	{
 		parse_error = true;
-		Log::Message(Log::LT_WARNING, "Error in data expression at %d. %s", index, message.c_str());
+		Log::Message(Log::LT_WARNING, "Error in data expression at %zu. %s", index, message.c_str());
 		Log::Message(Log::LT_WARNING, "  \"%s\"", expression.c_str());
 		
 		const size_t cursor_offset = size_t(index) + 3;
 		const String cursor_string = String(cursor_offset, ' ') + '^';
-		Log::Message(Log::LT_WARNING, cursor_string.c_str());
+		Log::Message(Log::LT_WARNING, "%s", cursor_string.c_str());
 	}
 	void Expected(String expected_symbols) {
 		const char c = Look();
@@ -758,7 +758,7 @@ public:
 	bool Error(String message) const
 	{
 		message = "Error during execution. " + message;
-		Log::Message(Log::LT_WARNING, message.c_str());
+		Log::Message(Log::LT_WARNING, "%s", message.c_str());
 		RMLUI_ERROR;
 		return false;
 	}
@@ -776,13 +776,13 @@ public:
 		}
 
 		if(success && !stack.empty())
-			Log::Message(Log::LT_WARNING, "Possible data interpreter stack corruption. Stack size is %d at end of execution (should be zero).", stack.size());
+			Log::Message(Log::LT_WARNING, "Possible data interpreter stack corruption. Stack size is %zu at end of execution (should be zero).", stack.size());
 
 		if(!success)
 		{
 			String program_str = DumpProgram();
-			Log::Message(Log::LT_WARNING, "Failed to execute program with %d instructions:", program.size());
-			Log::Message(Log::LT_WARNING, program_str.c_str());
+			Log::Message(Log::LT_WARNING, "Failed to execute program with %zu instructions:", program.size());
+			Log::Message(Log::LT_WARNING, "%s", program_str.c_str());
 		}
 
 		return success;

+ 1 - 1
Source/Core/Elements/ElementImage.cpp

@@ -298,7 +298,7 @@ void ElementImage::UpdateRect()
 
 			if (coords_list.size() != 4)
 			{
-				Log::Message(Log::LT_WARNING, "Element '%s' has an invalid 'rect' attribute; rect requires 4 space-separated values, found %d.", GetAddress().c_str(), coords_list.size());
+				Log::Message(Log::LT_WARNING, "Element '%s' has an invalid 'rect' attribute; rect requires 4 space-separated values, found %zu.", GetAddress().c_str(), coords_list.size());
 			}
 			else
 			{

+ 3 - 3
Source/Core/FontEngineDefault/FreeTypeInterface.cpp

@@ -255,21 +255,21 @@ static bool BuildGlyph(FT_Face ft_face, Character character, FontGlyphMap& glyph
 	FT_Error error = FT_Load_Glyph(ft_face, index, 0);
 	if (error != 0)
 	{
-		Log::Message(Log::LT_WARNING, "Unable to load glyph for character '%u' on the font face '%s %s'; error code: %d.", character, ft_face->family_name, ft_face->style_name, error);
+		Log::Message(Log::LT_WARNING, "Unable to load glyph for character '%u' on the font face '%s %s'; error code: %d.", (unsigned int)character, ft_face->family_name, ft_face->style_name, error);
 		return false;
 	}
 
 	error = FT_Render_Glyph(ft_face->glyph, FT_RENDER_MODE_NORMAL);
 	if (error != 0)
 	{
-		Log::Message(Log::LT_WARNING, "Unable to render glyph for character '%u' on the font face '%s %s'; error code: %d.", character, ft_face->family_name, ft_face->style_name, error);
+		Log::Message(Log::LT_WARNING, "Unable to render glyph for character '%u' on the font face '%s %s'; error code: %d.", (unsigned int)character, ft_face->family_name, ft_face->style_name, error);
 		return false;
 	}
 
 	auto result = glyphs.emplace(character, FontGlyph{});
 	if (!result.second)
 	{
-		Log::Message(Log::LT_WARNING, "Glyph character '%u' is already loaded in the font face '%s %s'.", character, ft_face->family_name, ft_face->style_name);
+		Log::Message(Log::LT_WARNING, "Glyph character '%u' is already loaded in the font face '%s %s'.", (unsigned int)character, ft_face->family_name, ft_face->style_name);
 		return false;
 	}
 

+ 1 - 1
Source/Core/StyleSheetParser.cpp

@@ -549,7 +549,7 @@ bool StyleSheetParser::Parse(MediaBlockList& style_sheets, Stream* _stream, int
 						current_block = MediaBlock{PropertyDictionary{}, UniquePtr<StyleSheet>(new StyleSheet())};
 					}
 
-					const int rule_line_number = (int)line_number;
+					const int rule_line_number = line_number;
 					
 					// Read the attributes
 					PropertyDictionary properties;

+ 1 - 1
Source/Core/StyleSheetParser.h

@@ -88,7 +88,7 @@ private:
 	// The name of the file we're parsing.
 	String stream_file_name;
 	// Current line number we're parsing.
-	size_t line_number;
+	int line_number;
 
 	// Parses properties from the parse buffer.
 	// @param property_parser An abstract parser which specifies how the properties are parsed and stored.

+ 1 - 1
Source/Lua/GlobalLuaFunctions.cpp

@@ -63,7 +63,7 @@ int LuaPrint(lua_State* L)
         lua_pop(L, 1);  /* pop result */
     }
     output += "\n";
-    Log::Message(Log::LT_INFO, output.c_str());
+    Log::Message(Log::LT_INFO, "%s", output.c_str());
     return 0;
 }
 

+ 1 - 1
Source/Lua/Log.cpp

@@ -73,7 +73,7 @@ int LogMessage(lua_State* L)
     Log::Type type = Log::Type((int)luaL_checkinteger(L,1));
     const char* str = luaL_checkstring(L,2);
     
-    Log::Message(type, str);
+    Log::Message(type, "%s", str);
     return 0;
 }