Skip to content

Commit 8034d8f

Browse files
committed
Declare endian read functions argument as a const pointer.
This is done for all functions of the form Curl_read[136][624]_[lb]e.
1 parent 945f60e commit 8034d8f

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

lib/curl_endian.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* | (__| |_| | _ <| |___
66
* \___|\___/|_| \_\_____|
77
*
8-
* Copyright (C) 1998 - 2015, Daniel Stenberg, <[email protected]>, et al.
8+
* Copyright (C) 1998 - 2016, Daniel Stenberg, <[email protected]>, et al.
99
*
1010
* This software is licensed as described in the file COPYING, which
1111
* you should have received as part of this distribution. The terms
@@ -37,7 +37,7 @@
3737
*
3838
* Returns the integer.
3939
*/
40-
unsigned short Curl_read16_le(unsigned char *buf)
40+
unsigned short Curl_read16_le(const unsigned char *buf)
4141
{
4242
return (unsigned short)(((unsigned short)buf[0]) |
4343
((unsigned short)buf[1] << 8));
@@ -56,7 +56,7 @@ unsigned short Curl_read16_le(unsigned char *buf)
5656
*
5757
* Returns the integer.
5858
*/
59-
unsigned int Curl_read32_le(unsigned char *buf)
59+
unsigned int Curl_read32_le(const unsigned char *buf)
6060
{
6161
return ((unsigned int)buf[0]) | ((unsigned int)buf[1] << 8) |
6262
((unsigned int)buf[2] << 16) | ((unsigned int)buf[3] << 24);
@@ -77,7 +77,7 @@ unsigned int Curl_read32_le(unsigned char *buf)
7777
* Returns the integer.
7878
*/
7979
#if defined(HAVE_LONGLONG)
80-
unsigned long long Curl_read64_le(unsigned char *buf)
80+
unsigned long long Curl_read64_le(const unsigned char *buf)
8181
{
8282
return ((unsigned long long)buf[0]) |
8383
((unsigned long long)buf[1] << 8) |
@@ -89,7 +89,7 @@ unsigned long long Curl_read64_le(unsigned char *buf)
8989
((unsigned long long)buf[7] << 56);
9090
}
9191
#else
92-
unsigned __int64 Curl_read64_le(unsigned char *buf)
92+
unsigned __int64 Curl_read64_le(const unsigned char *buf)
9393
{
9494
return ((unsigned __int64)buf[0]) | ((unsigned __int64)buf[1] << 8) |
9595
((unsigned __int64)buf[2] << 16) | ((unsigned __int64)buf[3] << 24) |
@@ -113,7 +113,7 @@ unsigned __int64 Curl_read64_le(unsigned char *buf)
113113
*
114114
* Returns the integer.
115115
*/
116-
unsigned short Curl_read16_be(unsigned char *buf)
116+
unsigned short Curl_read16_be(const unsigned char *buf)
117117
{
118118
return (unsigned short)(((unsigned short)buf[0] << 8) |
119119
((unsigned short)buf[1]));
@@ -132,7 +132,7 @@ unsigned short Curl_read16_be(unsigned char *buf)
132132
*
133133
* Returns the integer.
134134
*/
135-
unsigned int Curl_read32_be(unsigned char *buf)
135+
unsigned int Curl_read32_be(const unsigned char *buf)
136136
{
137137
return ((unsigned int)buf[0] << 24) | ((unsigned int)buf[1] << 16) |
138138
((unsigned int)buf[2] << 8) | ((unsigned int)buf[3]);
@@ -153,7 +153,7 @@ unsigned int Curl_read32_be(unsigned char *buf)
153153
* Returns the integer.
154154
*/
155155
#if defined(HAVE_LONGLONG)
156-
unsigned long long Curl_read64_be(unsigned char *buf)
156+
unsigned long long Curl_read64_be(const unsigned char *buf)
157157
{
158158
return ((unsigned long long)buf[0] << 56) |
159159
((unsigned long long)buf[1] << 48) |
@@ -165,7 +165,7 @@ unsigned long long Curl_read64_be(unsigned char *buf)
165165
((unsigned long long)buf[7]);
166166
}
167167
#else
168-
unsigned __int64 Curl_read64_be(unsigned char *buf)
168+
unsigned __int64 Curl_read64_be(const unsigned char *buf)
169169
{
170170
return ((unsigned __int64)buf[0] << 56) | ((unsigned __int64)buf[1] << 48) |
171171
((unsigned __int64)buf[2] << 40) | ((unsigned __int64)buf[3] << 32) |

lib/curl_endian.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* | (__| |_| | _ <| |___
88
* \___|\___/|_| \_\_____|
99
*
10-
* Copyright (C) 1998 - 2015, Daniel Stenberg, <[email protected]>, et al.
10+
* Copyright (C) 1998 - 2016, Daniel Stenberg, <[email protected]>, et al.
1111
*
1212
* This software is licensed as described in the file COPYING, which
1313
* you should have received as part of this distribution. The terms
@@ -23,32 +23,32 @@
2323
***************************************************************************/
2424

2525
/* Converts a 16-bit integer from little endian */
26-
unsigned short Curl_read16_le(unsigned char *buf);
26+
unsigned short Curl_read16_le(const unsigned char *buf);
2727

2828
/* Converts a 32-bit integer from little endian */
29-
unsigned int Curl_read32_le(unsigned char *buf);
29+
unsigned int Curl_read32_le(const unsigned char *buf);
3030

3131
#if (CURL_SIZEOF_CURL_OFF_T > 4)
3232
/* Converts a 64-bit integer from little endian */
3333
#if defined(HAVE_LONGLONG)
34-
unsigned long long Curl_read64_le(unsigned char *buf);
34+
unsigned long long Curl_read64_le(const unsigned char *buf);
3535
#else
36-
unsigned __int64 Curl_read64_le(unsigned char *buf);
36+
unsigned __int64 Curl_read64_le(const unsigned char *buf);
3737
#endif
3838
#endif
3939

4040
/* Converts a 16-bit integer from big endian */
41-
unsigned short Curl_read16_be(unsigned char *buf);
41+
unsigned short Curl_read16_be(const unsigned char *buf);
4242

4343
/* Converts a 32-bit integer from big endian */
44-
unsigned int Curl_read32_be(unsigned char *buf);
44+
unsigned int Curl_read32_be(const unsigned char *buf);
4545

4646
#if (CURL_SIZEOF_CURL_OFF_T > 4)
4747
/* Converts a 64-bit integer from big endian */
4848
#if defined(HAVE_LONGLONG)
49-
unsigned long long Curl_read64_be(unsigned char *buf);
49+
unsigned long long Curl_read64_be(const unsigned char *buf);
5050
#else
51-
unsigned __int64 Curl_read64_be(unsigned char *buf);
51+
unsigned __int64 Curl_read64_be(const unsigned char *buf);
5252
#endif
5353
#endif
5454

lib/smb.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* \___|\___/|_| \_\_____|
77
*
88
* Copyright (C) 2014, Bill Nagel <[email protected]>, Exacq Technologies
9-
* Copyright (C) 2015, Daniel Stenberg, <[email protected]>, et al.
9+
* Copyright (C) 2016, Daniel Stenberg, <[email protected]>, et al.
1010
*
1111
* This software is licensed as described in the file COPYING, which
1212
* you should have received as part of this distribution. The terms
@@ -308,8 +308,8 @@ static CURLcode smb_recv_message(struct connectdata *conn, void **msg)
308308
if(smbc->got < sizeof(unsigned int))
309309
return CURLE_OK;
310310

311-
nbt_size = Curl_read16_be((unsigned char *)(buf + sizeof(unsigned short))) +
312-
sizeof(unsigned int);
311+
nbt_size = Curl_read16_be((const unsigned char *)(buf +
312+
sizeof(unsigned short))) + sizeof(unsigned int);
313313
if(smbc->got < nbt_size)
314314
return CURLE_OK;
315315

@@ -320,7 +320,7 @@ static CURLcode smb_recv_message(struct connectdata *conn, void **msg)
320320
if(nbt_size >= msg_size + sizeof(unsigned short)) {
321321
/* Add the byte count */
322322
msg_size += sizeof(unsigned short) +
323-
Curl_read16_le((unsigned char *)&buf[msg_size]);
323+
Curl_read16_le((const unsigned char *)&buf[msg_size]);
324324
if(nbt_size < msg_size)
325325
return CURLE_READ_ERROR;
326326
}
@@ -781,9 +781,9 @@ static CURLcode smb_request_state(struct connectdata *conn, bool *done)
781781
next_state = SMB_CLOSE;
782782
break;
783783
}
784-
len = Curl_read16_le(((unsigned char *) msg) +
784+
len = Curl_read16_le(((const unsigned char *) msg) +
785785
sizeof(struct smb_header) + 11);
786-
off = Curl_read16_le(((unsigned char *) msg) +
786+
off = Curl_read16_le(((const unsigned char *) msg) +
787787
sizeof(struct smb_header) + 13);
788788
if(len > 0) {
789789
if(off + sizeof(unsigned int) + len > smbc->got) {
@@ -812,7 +812,7 @@ static CURLcode smb_request_state(struct connectdata *conn, bool *done)
812812
next_state = SMB_CLOSE;
813813
break;
814814
}
815-
len = Curl_read16_le(((unsigned char *) msg) +
815+
len = Curl_read16_le(((const unsigned char *) msg) +
816816
sizeof(struct smb_header) + 5);
817817
conn->data->req.bytecount += len;
818818
conn->data->req.offset += len;

0 commit comments

Comments
 (0)