Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Rev 50 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
43 magnus 1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 02_fix_warnings.dpatch by Russell Coker <russell@coker.com.au>
3
##
4
## DP: Get rid of warnings through the use of const and more correct types
5
 
6
@DPATCH@
7
 
55 magnus 8
--- a/src/dkim.cpp
9
+++ b/src/dkim.cpp
10
@@ -172,7 +172,7 @@ int DKIM_CALL DKIMVerifyInit( DKIMContex
43 magnus 11
 }
12
 
13
 
14
-int DKIM_CALL DKIMVerifyProcess( DKIMContext* pVerifyContext, char* szBuffer, int nBufLength )
15
+int DKIM_CALL DKIMVerifyProcess( DKIMContext* pVerifyContext, const char* const szBuffer, int nBufLength )
16
 {
17
        CDKIMVerify* pVerify = (CDKIMVerify*)ValidateContext( pVerifyContext, false );
18
 
55 magnus 19
@@ -226,13 +226,13 @@ void DKIM_CALL DKIMVerifyFree( DKIMConte
43 magnus 20
 }
21
 
22
 
23
-char* DKIM_CALL DKIMVersion()
24
+const char* DKIM_CALL DKIMVersion()
25
 {
26
        return VERSION_STRING;
27
 }
28
 
29
 
30
-static char* DKIMErrorStrings[-1-DKIM_MAX_ERROR] = {
31
+static const char* DKIMErrorStrings[-1-DKIM_MAX_ERROR] = {
32
        "DKIM_FAIL",
33
        "DKIM_BAD_SYNTAX",
34
        "DKIM_SIGNATURE_BAD",
55 magnus 35
@@ -259,7 +259,7 @@ static char* DKIMErrorStrings[-1-DKIM_MA
43 magnus 36
 };
37
 
38
 
39
-char* DKIM_CALL DKIMGetErrorString( int ErrorCode )
40
+const char* DKIM_CALL DKIMGetErrorString( int ErrorCode )
41
 {
42
        if (ErrorCode >= 0 || ErrorCode <= DKIM_MAX_ERROR)
43
                return "Unknown";
55 magnus 44
--- a/src/dkim.h
45
+++ b/src/dkim.h
46
@@ -154,14 +154,14 @@ int DKIM_CALL DKIMSignGetSig2( DKIMConte
43 magnus 47
 void DKIM_CALL DKIMSignFree( DKIMContext* pSignContext );
48
 
49
 int DKIM_CALL DKIMVerifyInit( DKIMContext* pVerifyContext, DKIMVerifyOptions* pOptions );
50
-int DKIM_CALL DKIMVerifyProcess( DKIMContext* pVerifyContext, char* szBuffer, int nBufLength );
51
+int DKIM_CALL DKIMVerifyProcess( DKIMContext* pVerifyContext, const char* szBuffer, int nBufLength );
52
 int DKIM_CALL DKIMVerifyResults( DKIMContext* pVerifyContext );
53
 int DKIM_CALL DKIMVerifyGetDetails( DKIMContext* pVerifyContext, int* nSigCount, DKIMVerifyDetails** pDetails, char* szPractices );
54
 void DKIM_CALL DKIMVerifyFree( DKIMContext* pVerifyContext );
55
 
56
-char *DKIM_CALL DKIMVersion();
57
+const char *DKIM_CALL DKIMVersion();
58
 
59
-char *DKIM_CALL DKIMGetErrorString( int ErrorCode );
60
+const char *DKIM_CALL DKIMGetErrorString( int ErrorCode );
61
 
62
 #ifdef __cplusplus
63
 }
55 magnus 64
--- a/src/dkimbase.cpp
65
+++ b/src/dkimbase.cpp
66
@@ -118,10 +118,10 @@ void CDKIMBase::Free( char* szBuffer )
43 magnus 67
 // Process - split buffers into lines without any CRs or LFs at the end.
68
 //
69
 ////////////////////////////////////////////////////////////////////////////////
70
-int CDKIMBase::Process( char* szBuffer, int nBufLength, bool bEOF )
71
+int CDKIMBase::Process( const char* szBuffer, int nBufLength, bool bEOF )
72
 {
73
-       char* p = szBuffer;
74
-       char* e = szBuffer + nBufLength;
75
+       const char* p = szBuffer;
76
+       const char* e = szBuffer + nBufLength;
77
 
78
        while( p < e )
79
        {
55 magnus 80
@@ -208,7 +208,8 @@ int CDKIMBase::ProcessFinal(void)
43 magnus 81
        {
82
                m_InHeaders = false;
83
                ProcessHeaders();
84
-               ProcessBody("", 0, true);
85
+               /* type conversion should be safe as length is zero */
86
+               ProcessBody((char *)"", 0, true);
87
        }
88
 
89
        return DKIM_SUCCESS;
55 magnus 90
@@ -338,9 +339,9 @@ string CDKIMBase::RelaxHeader( const str
43 magnus 91
 
92
        CompressSWSP(sTemp);
93
 
94
-       unsigned cpos = sTemp.find(':');
95
+       string::size_type cpos = sTemp.find(':');
96
 
97
-       if (cpos == -1)
98
+       if (cpos == string::npos)
99
        {
100
                // no colon?!
101
        }
55 magnus 102
--- a/src/dkimbase.h
103
+++ b/src/dkimbase.h
104
@@ -41,7 +41,7 @@ public:
43 magnus 105
 
106
        int Init(void);
107
 
108
-       int Process( char* szBuffer, int nBufLength, bool bEOF );
109
+       int Process( const char* szBuffer, int nBufLength, bool bEOF );
110
        int ProcessFinal(void);
111
 
112
        int Alloc( char*& szBuffer, int nRequiredSize );
55 magnus 113
--- a/src/dkimsign.cpp
114
+++ b/src/dkimsign.cpp
115
@@ -144,7 +144,7 @@ void CDKIMSign::Hash( const char* szBuff
43 magnus 116
 
117
        fwrite( szBuffer, 1, nBufLength, fpdebug );
118
 
119
-       /** END DEBUG CODE **/
120
+       ** END DEBUG CODE **/
121
 
122
        if( bAllmanOnly )
123
        {
55 magnus 124
@@ -555,7 +555,7 @@ void CDKIMSign::InitSig(void)
43 magnus 125
 //               if bFold, fold at cbrk char
126
 //
127
 ////////////////////////////////////////////////////////////////////////////////
128
-void CDKIMSign::AddTagToSig( char* Tag, const string &sValue, char cbrk, bool bFold )
129
+void CDKIMSign::AddTagToSig( const char* const Tag, const string &sValue, char cbrk, bool bFold )
130
 {
131
        int nTagLen = strlen(Tag);
132
 
55 magnus 133
@@ -583,10 +583,10 @@ void CDKIMSign::AddTagToSig( char* Tag,
43 magnus 134
 // AddTagToSig - add tag and numeric value to signature folding if necessary
135
 //
136
 ////////////////////////////////////////////////////////////////////////////////
137
-void CDKIMSign::AddTagToSig( char* Tag, unsigned long nValue )
138
+void CDKIMSign::AddTagToSig( const char* const Tag, unsigned long nValue )
139
 {
140
        char szValue[64];
141
-       sprintf( szValue, "%u", nValue );
142
+       sprintf( szValue, "%lu", nValue );
143
        AddTagToSig( Tag, szValue, 0, false );
144
 }
145
 
55 magnus 146
@@ -686,7 +686,7 @@ void CDKIMSign::AddFoldedValueToSig( con
43 magnus 147
 // GetSig - compute hash and return signature header in szSignature
148
 //
149
 ////////////////////////////////////////////////////////////////////////////////
150
-int CDKIMSign::GetSig( char* szPrivKey, char* szSignature, int nSigLength )
151
+int CDKIMSign::GetSig( char* szPrivKey, char* szSignature, unsigned nSigLength )
152
 {
153
        if( szPrivKey == NULL )
154
        {
55 magnus 155
@@ -794,7 +794,6 @@ int CDKIMSign::ConstructSignature( char*
43 magnus 156
        int size;
157
        int len;
158
        char* buf;
159
-       int pos = 0;
160
 
161
        // construct the DKIM-Signature: header and add to hash
162
        InitSig();
55 magnus 163
@@ -879,7 +878,7 @@ int CDKIMSign::ConstructSignature( char*
43 magnus 164
                }
165
                BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
166
                BIO_push(b64, bio);
167
-               if (BIO_write(b64, Hash, nHashLen) < nHashLen) 
168
+               if (BIO_write(b64, Hash, nHashLen) < (int)nHashLen) 
169
                {
170
                  BIO_free_all(b64);
171
                  return DKIM_OUT_OF_MEMORY;
55 magnus 172
@@ -993,7 +992,7 @@ int CDKIMSign::ConstructSignature( char*
43 magnus 173
     }
174
     BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
175
     BIO_push(b64, bio);
176
-    if (BIO_write(b64, sig, siglen) < siglen) 
177
+    if (BIO_write(b64, sig, siglen) < (int)siglen) 
178
        {
179
       OPENSSL_free(sig);
180
       BIO_free_all(b64);
55 magnus 181
--- a/src/dkimsign.h
182
+++ b/src/dkimsign.h
183
@@ -32,7 +32,7 @@ public:
43 magnus 184
 
185
        int Init( DKIMSignOptions* pOptions );
186
 
187
-       int GetSig( char* szPrivKey, char* szSignature, int nSigLength );
188
+       int GetSig( char* szPrivKey, char* szSignature, unsigned nSigLength );
189
        int GetSig2( char* szPrivKey, char** pszSignature );
190
 
191
        virtual int ProcessHeaders(void);
55 magnus 192
@@ -50,8 +50,8 @@ protected:
43 magnus 193
        bool ParseFromAddress( void );
194
 
195
        void InitSig(void);
196
-       void AddTagToSig( char* Tag, const string &sValue, char cbrk, bool bFold );
197
-       void AddTagToSig( char* Tag, unsigned long nValue );
198
+       void AddTagToSig( const char* const Tag, const string &sValue, char cbrk, bool bFold );
199
+       void AddTagToSig( const char* const Tag, unsigned long nValue );
200
        void AddInterTagSpace( int nSizeOfNextTag );
201
        void AddFoldedValueToSig( const string &sValue, char cbrk );
202
 
55 magnus 203
--- a/src/dkimverify.cpp
204
+++ b/src/dkimverify.cpp
205
@@ -442,7 +442,7 @@ int CDKIMVerify::GetResults(void)
43 magnus 206
 {
207
        ProcessFinal();
208
 
209
-       int SuccessCount=0;
210
+       unsigned int SuccessCount=0;
211
        int TestingFailures=0;
212
        int RealFailures=0;
213
 
55 magnus 214
@@ -643,7 +643,7 @@ void SignatureInfo::Hash( const char* sz
43 magnus 215
        /** END DEBUG CODE **/
216
 #endif
217
 
218
-       if (IsBody && BodyLength != -1)
219
+       if (IsBody && BodyLength != (unsigned)-1)
220
        {
221
                VerifiedBodyCount += nBufLength;
222
                if (VerifiedBodyCount > BodyLength)
55 magnus 223
@@ -1050,7 +1050,7 @@ int CDKIMVerify::ParseDKIMSignature( con
43 magnus 224
        // body count
225
        if (values[8] == NULL || !m_HonorBodyLengthTag)
226
        {
227
-               sig.BodyLength = -1;
228
+               sig.BodyLength = (unsigned)-1;
229
        }
230
        else
231
        {
55 magnus 232
@@ -1088,17 +1088,17 @@ int CDKIMVerify::ParseDKIMSignature( con
43 magnus 233
        // expiration time
234
        if (values[11] == NULL)
235
        {
236
-               sig.ExpireTime = -1;
237
+               sig.ExpireTime = (unsigned)-1;
238
        }
239
        else
240
        {
241
                if (!ParseUnsigned(values[11], &sig.ExpireTime))
242
                        return DKIM_BAD_SYNTAX;
243
 
244
-               if (sig.ExpireTime != -1)
245
+               if (sig.ExpireTime != (unsigned)-1)
246
                {
247
                        // the value of x= MUST be greater than the value of t= if both are present
248
-                       if (SignedTime != -1 && sig.ExpireTime <= SignedTime)
249
+                       if (SignedTime != (unsigned)-1 && sig.ExpireTime <= SignedTime)
250
                                return DKIM_BAD_SYNTAX;
251
 
252
                        // todo: if possible, use the received date/time instead of the current time
55 magnus 253
@@ -1200,7 +1200,7 @@ int CDKIMVerify::ProcessBody( char* szBu
43 magnus 254
 }
255
 
256
 
257
-SelectorInfo::SelectorInfo(const string &sSelector, const string &sDomain) : Selector(sSelector), Domain(sDomain)
258
+SelectorInfo::SelectorInfo(const string &sSelector, const string &sDomain) : Domain(sDomain), Selector(sSelector)
259
 {
260
        AllowSHA1 = true;
261
        AllowSHA256 = true;
55 magnus 262
@@ -1241,7 +1241,7 @@ int SelectorInfo::Parse( char* Buffer )
43 magnus 263
                        return DKIM_SELECTOR_INVALID;           // todo: maybe create a new error code for unsupported selector version
264
 
265
                // make sure v= is the first tag in the response        // todo: maybe don't enforce this, it seems unnecessary
266
-               for (int j=1; j<sizeof(values)/sizeof(values[0]); j++)
267
+               for (unsigned j=1; j<sizeof(values)/sizeof(values[0]); j++)
268
                {
269
                        if (values[j] != NULL && values[j] < values[0])
270
                        {
55 magnus 271
--- a/src/libdkimtest.cpp
272
+++ b/src/libdkimtest.cpp
273
@@ -60,9 +60,9 @@ int DKIM_CALL SelectorCallback(const cha
43 magnus 274
 int main(int argc, char* argv[])
275
 {
276
        int n;
277
-       char* PrivKeyFile = "test.pem";
278
-       char* MsgFile = "test.msg";
279
-       char* OutFile = "signed.msg";
280
+       const char* PrivKeyFile = "test.pem";
281
+       const char* MsgFile = "test.msg";
282
+       const char* OutFile = "signed.msg";
283
        int nPrivKeyLen;
284
        char PrivKey[2048];
285
        char Buffer[1024];