aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Aurich <paul@darkrain42.org>2011-04-27 10:42:20 -0700
committerSam Roberts <vieuxtech@gmail.com>2012-04-11 13:33:34 -0700
commit908ee2cce1740c3d873fe45b752c8aa1b1f3e306 (patch)
tree66168122e4b81645496325a0940d33d3c31ca42a /src
parentdd83e0a8494cfd28651b54c44d51e296ba16b8c4 (diff)
downloadluasocket-908ee2cce1740c3d873fe45b752c8aa1b1f3e306.tar.gz
luasocket-908ee2cce1740c3d873fe45b752c8aa1b1f3e306.tar.bz2
luasocket-908ee2cce1740c3d873fe45b752c8aa1b1f3e306.zip
Fix two crashes and add -Wshadow so that this can't happen again.
The two crashes are the s/const char *// changes in tcp.c. The rest is cleanup so it will build.
Diffstat (limited to 'src')
-rw-r--r--src/makefile2
-rw-r--r--src/mime.c44
-rw-r--r--src/tcp.c12
-rw-r--r--src/udp.c6
4 files changed, 32 insertions, 32 deletions
diff --git a/src/makefile b/src/makefile
index 701feb3..9768ba1 100644
--- a/src/makefile
+++ b/src/makefile
@@ -48,7 +48,7 @@ CC_linux=gcc
48DEF_linux=-DLUASOCKET_DEBUG \ 48DEF_linux=-DLUASOCKET_DEBUG \
49 -DLUASOCKET_API='__attribute__((visibility("default")))' \ 49 -DLUASOCKET_API='__attribute__((visibility("default")))' \
50 -DMIME_API='__attribute__((visibility("default")))' 50 -DMIME_API='__attribute__((visibility("default")))'
51CFLAGS_linux= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fpic \ 51CFLAGS_linux= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic \
52 -fvisibility=hidden 52 -fvisibility=hidden
53LDFLAGS_linux=-O -shared -fpic -o 53LDFLAGS_linux=-O -shared -fpic -o
54LD_linux=gcc 54LD_linux=gcc
diff --git a/src/mime.c b/src/mime.c
index 218e6f7..a1d7065 100644
--- a/src/mime.c
+++ b/src/mime.c
@@ -35,12 +35,12 @@ static int mime_global_eol(lua_State *L);
35static int mime_global_dot(lua_State *L); 35static int mime_global_dot(lua_State *L);
36 36
37static size_t dot(int c, size_t state, luaL_Buffer *buffer); 37static size_t dot(int c, size_t state, luaL_Buffer *buffer);
38static void b64setup(UC *b64unbase); 38static void b64setup(UC *base);
39static size_t b64encode(UC c, UC *input, size_t size, luaL_Buffer *buffer); 39static size_t b64encode(UC c, UC *input, size_t size, luaL_Buffer *buffer);
40static size_t b64pad(const UC *input, size_t size, luaL_Buffer *buffer); 40static size_t b64pad(const UC *input, size_t size, luaL_Buffer *buffer);
41static size_t b64decode(UC c, UC *input, size_t size, luaL_Buffer *buffer); 41static size_t b64decode(UC c, UC *input, size_t size, luaL_Buffer *buffer);
42 42
43static void qpsetup(UC *qpclass, UC *qpunbase); 43static void qpsetup(UC *class, UC *unbase);
44static void qpquote(UC c, luaL_Buffer *buffer); 44static void qpquote(UC c, luaL_Buffer *buffer);
45static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer); 45static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer);
46static size_t qpencode(UC c, UC *input, size_t size, 46static size_t qpencode(UC c, UC *input, size_t size,
@@ -149,12 +149,12 @@ static int mime_global_wrp(lua_State *L)
149/*-------------------------------------------------------------------------*\ 149/*-------------------------------------------------------------------------*\
150* Fill base64 decode map. 150* Fill base64 decode map.
151\*-------------------------------------------------------------------------*/ 151\*-------------------------------------------------------------------------*/
152static void b64setup(UC *b64unbase) 152static void b64setup(UC *unbase)
153{ 153{
154 int i; 154 int i;
155 for (i = 0; i <= 255; i++) b64unbase[i] = (UC) 255; 155 for (i = 0; i <= 255; i++) unbase[i] = (UC) 255;
156 for (i = 0; i < 64; i++) b64unbase[b64base[i]] = (UC) i; 156 for (i = 0; i < 64; i++) unbase[b64base[i]] = (UC) i;
157 b64unbase['='] = 0; 157 unbase['='] = 0;
158} 158}
159 159
160/*-------------------------------------------------------------------------*\ 160/*-------------------------------------------------------------------------*\
@@ -349,24 +349,24 @@ static int mime_global_unb64(lua_State *L)
349* Split quoted-printable characters into classes 349* Split quoted-printable characters into classes
350* Precompute reverse map for encoding 350* Precompute reverse map for encoding
351\*-------------------------------------------------------------------------*/ 351\*-------------------------------------------------------------------------*/
352static void qpsetup(UC *qpclass, UC *qpunbase) 352static void qpsetup(UC *cl, UC *unbase)
353{ 353{
354 int i; 354 int i;
355 for (i = 0; i < 256; i++) qpclass[i] = QP_QUOTED; 355 for (i = 0; i < 256; i++) cl[i] = QP_QUOTED;
356 for (i = 33; i <= 60; i++) qpclass[i] = QP_PLAIN; 356 for (i = 33; i <= 60; i++) cl[i] = QP_PLAIN;
357 for (i = 62; i <= 126; i++) qpclass[i] = QP_PLAIN; 357 for (i = 62; i <= 126; i++) cl[i] = QP_PLAIN;
358 qpclass['\t'] = QP_IF_LAST; 358 cl['\t'] = QP_IF_LAST;
359 qpclass[' '] = QP_IF_LAST; 359 cl[' '] = QP_IF_LAST;
360 qpclass['\r'] = QP_CR; 360 cl['\r'] = QP_CR;
361 for (i = 0; i < 256; i++) qpunbase[i] = 255; 361 for (i = 0; i < 256; i++) unbase[i] = 255;
362 qpunbase['0'] = 0; qpunbase['1'] = 1; qpunbase['2'] = 2; 362 unbase['0'] = 0; unbase['1'] = 1; unbase['2'] = 2;
363 qpunbase['3'] = 3; qpunbase['4'] = 4; qpunbase['5'] = 5; 363 unbase['3'] = 3; unbase['4'] = 4; unbase['5'] = 5;
364 qpunbase['6'] = 6; qpunbase['7'] = 7; qpunbase['8'] = 8; 364 unbase['6'] = 6; unbase['7'] = 7; unbase['8'] = 8;
365 qpunbase['9'] = 9; qpunbase['A'] = 10; qpunbase['a'] = 10; 365 unbase['9'] = 9; unbase['A'] = 10; unbase['a'] = 10;
366 qpunbase['B'] = 11; qpunbase['b'] = 11; qpunbase['C'] = 12; 366 unbase['B'] = 11; unbase['b'] = 11; unbase['C'] = 12;
367 qpunbase['c'] = 12; qpunbase['D'] = 13; qpunbase['d'] = 13; 367 unbase['c'] = 12; unbase['D'] = 13; unbase['d'] = 13;
368 qpunbase['E'] = 14; qpunbase['e'] = 14; qpunbase['F'] = 15; 368 unbase['E'] = 14; unbase['e'] = 14; unbase['F'] = 15;
369 qpunbase['f'] = 15; 369 unbase['f'] = 15;
370} 370}
371 371
372/*-------------------------------------------------------------------------*\ 372/*-------------------------------------------------------------------------*\
diff --git a/src/tcp.c b/src/tcp.c
index 3204b40..658f255 100644
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -40,7 +40,7 @@ static int meth_setfd(lua_State *L);
40static int meth_dirty(lua_State *L); 40static int meth_dirty(lua_State *L);
41 41
42/* tcp object methods */ 42/* tcp object methods */
43static luaL_reg tcp[] = { 43static luaL_reg tcp_methods[] = {
44 {"__gc", meth_close}, 44 {"__gc", meth_close},
45 {"__tostring", auxiliar_tostring}, 45 {"__tostring", auxiliar_tostring},
46 {"accept", meth_accept}, 46 {"accept", meth_accept},
@@ -88,9 +88,9 @@ static luaL_reg func[] = {
88int tcp_open(lua_State *L) 88int tcp_open(lua_State *L)
89{ 89{
90 /* create classes */ 90 /* create classes */
91 auxiliar_newclass(L, "tcp{master}", tcp); 91 auxiliar_newclass(L, "tcp{master}", tcp_methods);
92 auxiliar_newclass(L, "tcp{client}", tcp); 92 auxiliar_newclass(L, "tcp{client}", tcp_methods);
93 auxiliar_newclass(L, "tcp{server}", tcp); 93 auxiliar_newclass(L, "tcp{server}", tcp_methods);
94 /* create class groups */ 94 /* create class groups */
95 auxiliar_add2group(L, "tcp{master}", "tcp{any}"); 95 auxiliar_add2group(L, "tcp{master}", "tcp{any}");
96 auxiliar_add2group(L, "tcp{client}", "tcp{any}"); 96 auxiliar_add2group(L, "tcp{client}", "tcp{any}");
@@ -359,7 +359,7 @@ static const char *trybind6(const char *localaddr, const char *localserv,
359 for (iterator = resolved; iterator; iterator = iterator->ai_next) { 359 for (iterator = resolved; iterator; iterator = iterator->ai_next) {
360 /* create a new socket each time because parameters 360 /* create a new socket each time because parameters
361 * may have changed */ 361 * may have changed */
362 const char *err = socket_strerror(socket_create(&tcp->sock, 362 err = socket_strerror(socket_create(&tcp->sock,
363 iterator->ai_family, iterator->ai_socktype, 363 iterator->ai_family, iterator->ai_socktype,
364 iterator->ai_protocol)); 364 iterator->ai_protocol));
365 /* if failed to create socket, bail out */ 365 /* if failed to create socket, bail out */
@@ -445,7 +445,7 @@ static const char *tryconnect6(const char *remoteaddr, const char *remoteserv,
445 p_timeout tm = timeout_markstart(&tcp->tm); 445 p_timeout tm = timeout_markstart(&tcp->tm);
446 /* create new socket if one wasn't created by the bind stage */ 446 /* create new socket if one wasn't created by the bind stage */
447 if (tcp->sock == SOCKET_INVALID) { 447 if (tcp->sock == SOCKET_INVALID) {
448 const char *err = socket_strerror(socket_create(&tcp->sock, 448 err = socket_strerror(socket_create(&tcp->sock,
449 iterator->ai_family, iterator->ai_socktype, 449 iterator->ai_family, iterator->ai_socktype,
450 iterator->ai_protocol)); 450 iterator->ai_protocol));
451 if (err != NULL) { 451 if (err != NULL) {
diff --git a/src/udp.c b/src/udp.c
index e3c86e7..0f9b7cc 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -44,7 +44,7 @@ static int meth_setfd(lua_State *L);
44static int meth_dirty(lua_State *L); 44static int meth_dirty(lua_State *L);
45 45
46/* udp object methods */ 46/* udp object methods */
47static luaL_reg udp[] = { 47static luaL_reg udp_methods[] = {
48 {"__gc", meth_close}, 48 {"__gc", meth_close},
49 {"__tostring", auxiliar_tostring}, 49 {"__tostring", auxiliar_tostring},
50 {"close", meth_close}, 50 {"close", meth_close},
@@ -98,8 +98,8 @@ static luaL_reg func[] = {
98int udp_open(lua_State *L) 98int udp_open(lua_State *L)
99{ 99{
100 /* create classes */ 100 /* create classes */
101 auxiliar_newclass(L, "udp{connected}", udp); 101 auxiliar_newclass(L, "udp{connected}", udp_methods);
102 auxiliar_newclass(L, "udp{unconnected}", udp); 102 auxiliar_newclass(L, "udp{unconnected}", udp_methods);
103 /* create class groups */ 103 /* create class groups */
104 auxiliar_add2group(L, "udp{connected}", "udp{any}"); 104 auxiliar_add2group(L, "udp{connected}", "udp{any}");
105 auxiliar_add2group(L, "udp{unconnected}", "udp{any}"); 105 auxiliar_add2group(L, "udp{unconnected}", "udp{any}");