summaryrefslogtreecommitdiff
blob: eed38b4785fa6cf9a47308038738116a6023db2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
qt-bugs@ issue : N171087
Trolltech task ID : 
bugs.kde.org number :
applied: no
author: Dirk Mueller <mueller@kde.org>

This patch fixes various code issues with handling format strings
None of them seem to be exceptionally bad, but its better safe
than sorry.


--- src/corelib/global/qglobal.h
+++ src/corelib/global/qglobal.h
@@ -1266,8 +1266,16 @@ Q_CORE_EXPORT void qFatal(const char *, 
 #ifdef QT3_SUPPORT
 Q_CORE_EXPORT QT3_SUPPORT void qSystemWarning(const char *msg, int code = -1);
 #endif /* QT3_SUPPORT */
-Q_CORE_EXPORT void qErrnoWarning(int code, const char *msg, ...);
-Q_CORE_EXPORT void qErrnoWarning(const char *msg, ...);
+Q_CORE_EXPORT void qErrnoWarning(int code, const char *msg, ...)
+#if defined(Q_CC_GNU) && !defined(__INSURE__)
+    __attribute__ ((format (printf, 2, 3)))
+#endif
+    ;
+Q_CORE_EXPORT void qErrnoWarning(const char *msg, ...)
+#if defined(Q_CC_GNU) && !defined(__INSURE__)
+    __attribute__ ((format (printf, 1, 2)))
+#endif
+    ;
 
 #if (defined(QT_NO_DEBUG_OUTPUT) || defined(QT_NO_TEXTSTREAM)) && !defined(QT_NO_DEBUG_STREAM)
 #define QT_NO_DEBUG_STREAM
--- src/corelib/tools/qbytearray.h
+++ src/corelib/tools/qbytearray.h
@@ -71,8 +71,16 @@ Q_CORE_EXPORT int qstricmp(const char *,
 Q_CORE_EXPORT int qstrnicmp(const char *, const char *, uint len);
 
 // implemented in qvsnprintf.cpp
-Q_CORE_EXPORT int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap);
-Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt, ...);
+Q_CORE_EXPORT int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
+#if defined(Q_CC_GNU) && !defined(__INSURE__)
+        __attribute__ ((format (printf, 3, 0)))
+#endif
+    ;
+Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt, ...)
+#if defined(Q_CC_GNU) && !defined(__INSURE__)
+        __attribute__ ((format (printf, 3, 4)))
+#endif
+    ;
 
 #ifdef QT3_SUPPORT
 inline QT3_SUPPORT void *qmemmove(void *dst, const void *src, uint len)
--- src/gui/painting/qprintengine_pdf_p.h
+++ src/gui/painting/qprintengine_pdf_p.h
@@ -148,7 +148,11 @@ private:
     void writePage();
 
     int addXrefEntry(int object, bool printostr = true);
-    void xprintf(const char* fmt, ...);
+    void xprintf(const char* fmt, ...)
+#if defined(Q_CC_GNU) && !defined(__INSURE__)
+        __attribute__ ((format (printf, 2, 3)))
+#endif
+        ;
     inline void write(const QByteArray &data) {
         stream->writeRawData(data.constData(), data.size());
         streampos += data.size();
--- src/gui/painting/qprintengine_pdf.cpp
+++ src/gui/painting/qprintengine_pdf.cpp
@@ -386,9 +386,8 @@ int QPdfEnginePrivate::addConstantAlphaO
         object = addXrefEntry(-1);
         QByteArray alphaDef;
         QPdf::ByteStream s(&alphaDef);
-        s << "<< /ca " << (alpha/qreal(255.)) << ">>\n";
-        xprintf(alphaDef.constData());
-        xprintf("endobj\n");
+        s << "<< /ca " << (alpha/qreal(255.)) << ">>";
+        xprintf("%s\nendobj\n", alphaDef.constData());
     }
     currentPage->graphicStates.append(object);
     return object;
--- src/qt3support/tools/q3gcache.cpp
+++ src/qt3support/tools/q3gcache.cpp
@@ -622,7 +622,7 @@ void Q3GCache::statistics() const
 #if defined(QT_DEBUG)
     QString line;
     line.fill(QLatin1Char('*'), 80);
-    qDebug(line.ascii());
+    qDebug("%s", line.ascii());
     qDebug("CACHE STATISTICS:");
     qDebug("cache contains %d item%s, with a total cost of %d",
 	   count(), count() != 1 ? "s" : "", tCost);
@@ -643,7 +643,7 @@ void Q3GCache::statistics() const
 	   lruList->dumps != 1 ? "have" : "has", lruList->dumpCosts);
     qDebug("Statistics from internal dictionary class:");
     dict->statistics();
-    qDebug(line.ascii());
+    qDebug("%s", line.ascii());
 #endif
 }
 
--- src/qt3support/tools/q3gdict.cpp
+++ src/qt3support/tools/q3gdict.cpp
@@ -828,11 +828,11 @@ void Q3GDict::statistics() const
     QString line;
     line.fill(QLatin1Char('-'), 60);
     double real, ideal;
-    qDebug(line.ascii());
+    qDebug("%s", line.ascii());
     qDebug("DICTIONARY STATISTICS:");
     if (count() == 0) {
         qDebug("Empty!");
-        qDebug(line.ascii());
+        qDebug("%s", line.ascii());
         return;
     }
     real = 0.0;
@@ -853,7 +853,7 @@ void Q3GDict::statistics() const
         while (b--)
             *pbuf++ = '*';
         *pbuf = '\0';
-        qDebug(buf);
+        qDebug("%s", buf);
         i++;
     }
     qDebug("Array size = %d", size());
@@ -861,7 +861,7 @@ void Q3GDict::statistics() const
     qDebug("Real dist  = %g", real);
     qDebug("Rand dist  = %g", ideal);
     qDebug("Real/Rand  = %g", real/ideal);
-    qDebug(line.ascii());
+    qDebug("%s", line.ascii());
 #endif // QT_DEBUG
 }
 
--- src/qt3support/tools/q3cstring.h
+++ src/qt3support/tools/q3cstring.h
@@ -57,7 +57,11 @@ public:
     }
 
     Q3CString        copy()        const { return *this; }
-    Q3CString    &sprintf(const char *format, ...);
+    Q3CString    &sprintf(const char *format, ...)
+#if defined(Q_CC_GNU) && !defined(__INSURE__)
+        __attribute__ ((format (printf, 2, 3)))
+#endif
+        ;
 
     Q3CString        left(uint len)  const { return QByteArray::left(len); }
     Q3CString        right(uint len) const { return QByteArray::right(len); }
--- tools/designer/src/lib/uilib/formbuilderextra.cpp
+++ tools/designer/src/lib/uilib/formbuilderextra.cpp
@@ -33,9 +33,7 @@ namespace QFormInternal {
 #endif

 void uiLibWarning(const QString &message) {
-    QString prefixedMessage = QLatin1String("Designer: ");
-    prefixedMessage += message;
-    qWarning(prefixedMessage.toUtf8().constData());
+    qWarning("Designer: %s", qPrintable(message));
 }

 QFormBuilderExtra::QFormBuilderExtra() :
--- tools/designer/src/lib/shared/qdesigner_utils.cpp
+++ tools/designer/src/lib/shared/qdesigner_utils.cpp
@@ -40,9 +40,7 @@ namespace qdesigner_internal
 {
     QDESIGNER_SHARED_EXPORT void designerWarning(const QString &message)
     {
-        QString prefixedMessage = QLatin1String("Designer: ");
-        prefixedMessage += message;
-        qWarning(prefixedMessage.toUtf8().constData());
+        qWarning("Designer: %s", qPrintable(message));
     }

     QString EnumType::id() const
--- tools/qtestlib/src/qtest_global.h
+++ tools/qtestlib/src/qtest_global.h
@@ -59,7 +59,11 @@ namespace QTest
     enum SkipMode { SkipSingle = 1, SkipAll = 2 };
     enum TestFailMode { Abort = 1, Continue = 2 };
 
-    int Q_TESTLIB_EXPORT qt_snprintf(char *str, int size, const char *format, ...);
+    int Q_TESTLIB_EXPORT qt_snprintf(char *str, int size, const char *format, ...)
+#if defined(Q_CC_GNU) && !defined(__INSURE__)
+        __attribute__ ((format (printf, 3, 4)))
+#endif
+        ;
 }
 
 QT_END_HEADER
--- tools/assistant/config.cpp
+++ tools/assistant/config.cpp
@@ -73,12 +73,12 @@ Config *Config::loadConfig(const QString
 
     QFile file(profileFileName);
     if (!file.exists()) {
-        qWarning( (QLatin1String("File does not exist: ") + profileFileName).toAscii().constData() );
+        qWarning( "File does not exist: %s", qPrintable(profileFileName) );
         return 0;
     }
     DocuParser *parser = DocuParser::createParser( profileFileName );
     if (!parser) {
-        qWarning( (QLatin1String("Failed to create parser for file: ") + profileFileName).toAscii().constData() );
+        qWarning( "Failed to create parser for file: %s", qPrintable(profileFileName) );
         return 0;
     }
     if (parser->parserVersion() < DocuParser::Qt320) {
@@ -89,7 +89,7 @@ Config *Config::loadConfig(const QString
     parser->parse(&file);
     config->profil = profileParser->profile();
     if (!config->profil) {
-        qWarning( (QLatin1String("Config::loadConfig(), no profile in: ") + profileFileName).toAscii().constData() );
+        qWarning( "Config::loadConfig(), no profile in: %s", qPrintable(profileFileName) );
         return 0;
     }
     config->profil->setProfileType(Profile::UserProfile);
--- tools/assistant/index.cpp
+++ tools/assistant/index.cpp
@@ -180,7 +180,7 @@ void Index::parseDocument( const QString
 {
     QFile file( filename );
     if ( !file.open(QFile::ReadOnly) ) {
-        qWarning( (QLatin1String("can not open file ") + filename).toAscii().constData() );
+        qWarning( "can not open file %s", qPrintable(filename) );
         return;
     }
 
@@ -352,7 +352,7 @@ QString Index::getDocumentTitle( const Q
 
     QFile file( fileName );
     if ( !file.open( QFile::ReadOnly ) ) {
-        qWarning( (QLatin1String("cannot open file ") + fileName).toAscii().constData() );
+        qWarning( "cannot open file %s", qPrintable(fileName) );
         return fileName;
     }
     QTextStream s( &file );
@@ -474,7 +474,7 @@ bool Index::searchForPattern( const QStr
     QString fName = url.toLocalFile();
     QFile file( fName );
     if ( !file.open( QFile::ReadOnly ) ) {
-        qWarning( (QLatin1String("cannot open file ") + fName).toAscii().constData() );
+        qWarning( "cannot open file %s", qPrintable(fName) );
         return false;
     }
 
--- tools/linguist/shared/profileevaluator.h
+++ tools/linguist/shared/profileevaluator.h
@@ -88,7 +88,11 @@ protected:
 
 private:
     void logMessage(const QString &msg, MessageType mt = MT_DebugLevel2);
-    void logMessage(MessageType mt, const char *msg, ...);
+    void logMessage(MessageType mt, const char *msg, ...)
+#if defined(Q_CC_GNU) && !defined(__INSURE__)
+        __attribute__ ((format (printf, 3, 4)))
+#endif
+        ;
     QString expandVariableReferences(const QString &value);
     QString evaluateExpandFunction(const QByteArray &func, const QString &arguments);