From 7700f0f5c0ab90bf052e33fa0ddd2f2aa7e7893e Mon Sep 17 00:00:00 2001 From: lpleahy Date: Fri, 17 Feb 2012 23:43:35 +0000 Subject: [PATCH] * StdLib.dsc was changed to always build the sockets code. * Fix errors detected by the GCC compiler (pointer conversions and format mismatches). * Worked around a GCC flow analysis issue in base64.c where the compiler is convinced that there is a path through the code where "input" is used but not initialized. * Added EFIAPI to the file system operation routines for sockets to match the API declaration. Note for GCC, the meaning of "l" and "L" are different in printf and sscanf format strings. The lower case "l" indicates a 32-bit value where the capital "L" indicates a 64-bit value. The native (default) integer size may be represented by a size letter of "n". Signed-off-by: lpleahy git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13023 6f19259b-4bc3-4df7-8a09-765794883524 --- StdLib/BsdSocketLib/SocketInternals.h | 4 ++++ StdLib/BsdSocketLib/base64.c | 1 + StdLib/BsdSocketLib/close.c | 1 + StdLib/BsdSocketLib/getaddrinfo.c | 4 ++-- StdLib/BsdSocketLib/inet_net_ntop.c | 2 +- StdLib/BsdSocketLib/ns_ntoa.c | 2 +- StdLib/BsdSocketLib/ns_print.c | 18 +++++++++--------- StdLib/BsdSocketLib/poll.c | 1 + StdLib/BsdSocketLib/read.c | 1 + StdLib/BsdSocketLib/res_debug.c | 4 ++-- StdLib/BsdSocketLib/res_send.c | 9 ++++----- StdLib/BsdSocketLib/write.c | 1 + StdLib/StdLib.dsc | 6 +++--- 13 files changed, 31 insertions(+), 23 deletions(-) diff --git a/StdLib/BsdSocketLib/SocketInternals.h b/StdLib/BsdSocketLib/SocketInternals.h index 1b19869c0d..c30f7fb661 100644 --- a/StdLib/BsdSocketLib/SocketInternals.h +++ b/StdLib/BsdSocketLib/SocketInternals.h @@ -82,6 +82,7 @@ BslFdToSocketProtocol ( **/ int +EFIAPI BslSocketClose ( struct __filedes * pDescriptor ); @@ -113,6 +114,7 @@ BslSocketCloseWork ( **/ short +EFIAPI BslSocketPoll ( IN struct __filedes * pDescriptor, IN short Events @@ -152,6 +154,7 @@ BslSocketProtocolToFd ( **/ ssize_t +EFIAPI BslSocketRead ( struct __filedes *pDescriptor, off_t * pOffset, @@ -172,6 +175,7 @@ BslSocketRead ( **/ ssize_t +EFIAPI BslSocketWrite ( struct __filedes *pDescriptor, off_t * pOffset, diff --git a/StdLib/BsdSocketLib/base64.c b/StdLib/BsdSocketLib/base64.c index d8c588d19d..363ee18591 100644 --- a/StdLib/BsdSocketLib/base64.c +++ b/StdLib/BsdSocketLib/base64.c @@ -171,6 +171,7 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) { u_char output[4]; size_t i; + input[0] = input[1] = input[2] = '\0'; while (2 < srclength) { input[0] = *src++; input[1] = *src++; diff --git a/StdLib/BsdSocketLib/close.c b/StdLib/BsdSocketLib/close.c index 3dfeb2bf18..f3f7e98cba 100644 --- a/StdLib/BsdSocketLib/close.c +++ b/StdLib/BsdSocketLib/close.c @@ -94,6 +94,7 @@ BslSocketCloseWork ( **/ int +EFIAPI BslSocketClose ( struct __filedes * pDescriptor ) diff --git a/StdLib/BsdSocketLib/getaddrinfo.c b/StdLib/BsdSocketLib/getaddrinfo.c index c8ed7848a4..5a0baf6d45 100644 --- a/StdLib/BsdSocketLib/getaddrinfo.c +++ b/StdLib/BsdSocketLib/getaddrinfo.c @@ -557,8 +557,8 @@ getaddrinfo(const char *hostname, const char *servname, } static const ns_dtab dtab[] = { - NS_FILES_CB(_files_getaddrinfo, NULL) - { NSSRC_DNS, _dns_getaddrinfo, NULL }, /* force -DHESIOD */ + NS_FILES_CB(((nss_method)_files_getaddrinfo), NULL) + { NSSRC_DNS, ((nss_method)_dns_getaddrinfo), NULL }, /* force -DHESIOD */ NS_NIS_CB(_yp_getaddrinfo, NULL) NS_NULL_CB }; diff --git a/StdLib/BsdSocketLib/inet_net_ntop.c b/StdLib/BsdSocketLib/inet_net_ntop.c index 3925727878..e7411434f9 100644 --- a/StdLib/BsdSocketLib/inet_net_ntop.c +++ b/StdLib/BsdSocketLib/inet_net_ntop.c @@ -126,7 +126,7 @@ inet_net_ntop_ipv4( if (dst != odst) *dst++ = '.'; m = ((1 << b) - 1) << (8 - b); - dst += SPRINTF((dst, "%u", *src & m)); + dst += SPRINTF((dst, "%u", ((unsigned int)(*src & m)))); size -= (size_t)(dst - t); } diff --git a/StdLib/BsdSocketLib/ns_ntoa.c b/StdLib/BsdSocketLib/ns_ntoa.c index 1162b4d69a..d079dc8669 100644 --- a/StdLib/BsdSocketLib/ns_ntoa.c +++ b/StdLib/BsdSocketLib/ns_ntoa.c @@ -55,7 +55,7 @@ ns_ntoa( u_char *uplim = up + 6; net.net_e = addr.x_net; - sprintf(obuf, "%lx", (u_long)ntohl(net.long_e)); + sprintf(obuf, "%Lx", (u_long)ntohl(net.long_e)); cp = spectHex(obuf); cp2 = cp + 1; while (*up==0 && up < uplim) up++; diff --git a/StdLib/BsdSocketLib/ns_print.c b/StdLib/BsdSocketLib/ns_print.c index ff7047a1fd..a5d8ad3d7d 100644 --- a/StdLib/BsdSocketLib/ns_print.c +++ b/StdLib/BsdSocketLib/ns_print.c @@ -228,7 +228,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, /* Serial number. */ t = ns_get32(rdata); rdata += NS_INT32SZ; T(addstr("\t\t\t\t\t", 5, &buf, &buflen)); - len = SPRINTF((tmp, "%lu", t)); + len = SPRINTF((tmp, "%Lu", t)); T(addstr(tmp, len, &buf, &buflen)); T(spaced = addtab(len, 16, spaced, &buf, &buflen)); T(addstr("; serial\n", 9, &buf, &buflen)); @@ -284,7 +284,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, /* Priority. */ t = ns_get16(rdata); rdata += NS_INT16SZ; - len = SPRINTF((tmp, "%u ", t)); + len = SPRINTF((tmp, "%u ", (unsigned int)t)); T(addstr(tmp, len, &buf, &buflen)); /* Target. */ @@ -302,7 +302,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, /* Priority. */ t = ns_get16(rdata); rdata += NS_INT16SZ; - len = SPRINTF((tmp, "%u ", t)); + len = SPRINTF((tmp, "%u ", (unsigned int)t)); T(addstr(tmp, len, &buf, &buflen)); /* Name1. */ @@ -363,7 +363,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, /* Order, Precedence. */ order = ns_get16(rdata); rdata += NS_INT16SZ; preference = ns_get16(rdata); rdata += NS_INT16SZ; - len = SPRINTF((t, "%u %u ", order, preference)); + len = SPRINTF((t, "%u %u ", (unsigned int)order, (unsigned int)preference)); T(addstr(t, len, &buf, &buflen)); /* Flags. */ @@ -404,7 +404,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, priority = ns_get16(rdata); rdata += NS_INT16SZ; weight = ns_get16(rdata); rdata += NS_INT16SZ; port = ns_get16(rdata); rdata += NS_INT16SZ; - len = SPRINTF((t, "%u %u %u ", priority, weight, port)); + len = SPRINTF((t, "%u %u %u ", (unsigned int)priority, (unsigned int)weight, (unsigned int)port)); T(addstr(t, len, &buf, &buflen)); /* Server. */ @@ -477,7 +477,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, protocol = *rdata++; algorithm = *rdata++; len = SPRINTF((tmp, "0x%04x %u %u", - keyflags, protocol, algorithm)); + (unsigned int)keyflags, (unsigned int)protocol, (unsigned int)algorithm)); T(addstr(tmp, len, &buf, &buflen)); /* Public key data. */ @@ -516,8 +516,8 @@ ns_sprintrrf(const u_char *msg, size_t msglen, algorithm = *rdata++; labels = *rdata++; t = ns_get32(rdata); rdata += NS_INT32SZ; - len = SPRINTF((tmp, " %s %d %lu ", - p_type((int)type), algorithm, t)); + len = SPRINTF((tmp, " %s %d %Lu ", + p_type((int)type), (int)algorithm, t)); T(addstr(tmp, len, &buf, &buflen)); if (labels != (u_int)dn_count_labels(name)) goto formerr; @@ -534,7 +534,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, /* Signature Footprint. */ footprint = ns_get16(rdata); rdata += NS_INT16SZ; - len = SPRINTF((tmp, "%u ", footprint)); + len = SPRINTF((tmp, "%u ", (unsigned int)footprint)); T(addstr(tmp, len, &buf, &buflen)); /* Signer's name. */ diff --git a/StdLib/BsdSocketLib/poll.c b/StdLib/BsdSocketLib/poll.c index 336924d556..dc17567662 100644 --- a/StdLib/BsdSocketLib/poll.c +++ b/StdLib/BsdSocketLib/poll.c @@ -26,6 +26,7 @@ **/ short +EFIAPI BslSocketPoll ( IN struct __filedes * pDescriptor, IN short Events diff --git a/StdLib/BsdSocketLib/read.c b/StdLib/BsdSocketLib/read.c index 293c101463..f4348a51dc 100644 --- a/StdLib/BsdSocketLib/read.c +++ b/StdLib/BsdSocketLib/read.c @@ -33,6 +33,7 @@ **/ ssize_t +EFIAPI BslSocketRead ( struct __filedes *pDescriptor, off_t * pOffset, diff --git a/StdLib/BsdSocketLib/res_debug.c b/StdLib/BsdSocketLib/res_debug.c index 5cdc674572..5dc0302eec 100644 --- a/StdLib/BsdSocketLib/res_debug.c +++ b/StdLib/BsdSocketLib/res_debug.c @@ -243,7 +243,7 @@ fp_nquery(const u_char *msg, int len, FILE *file) { if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || rcode) fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n", - _res_opcodes[opcode], _res_resultcodes[rcode], id); + _res_opcodes[opcode], _res_resultcodes[rcode], (int)id); if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX)) putc(';', file); if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) { @@ -536,7 +536,7 @@ p_option(u_long option) { case RES_DNSRCH: return "dnsrch"; case RES_INSECURE1: return "insecure1"; case RES_INSECURE2: return "insecure2"; - default: sprintf(nbuf, "?0x%lx?", (u_long)option); + default: sprintf(nbuf, "?0x%Lx?", (u_long)option); return (nbuf); } } diff --git a/StdLib/BsdSocketLib/res_send.c b/StdLib/BsdSocketLib/res_send.c index 0b887e79d0..d9ae46558e 100644 --- a/StdLib/BsdSocketLib/res_send.c +++ b/StdLib/BsdSocketLib/res_send.c @@ -114,7 +114,6 @@ static char rcsid[] = "$Id: res_send.c,v 1.1.1.1 2003/11/19 01:51:39 kyu3 Exp $" #endif #ifdef NOPOLL /* libc_r doesn't wrap poll yet() */ -static int use_poll = 0; #else #include static int use_poll = 1; /* adapt to poll() syscall availability */ @@ -855,10 +854,10 @@ read_len: ((_res.pfcode & RES_PRF_REPLY) && (_res.pfcode & RES_PRF_HEAD1)), (stdout, ";; got answer:\n")); - DprintQ((_res.options & RES_DEBUG) || - (_res.pfcode & RES_PRF_REPLY), - (stdout, ""), - ans, (resplen>anssiz)?anssiz:resplen); + if((_res.options & RES_DEBUG) || + (_res.pfcode & RES_PRF_REPLY)) { + __fp_nquery(ans, (resplen>anssiz)?anssiz:resplen, stdout); + } /* * If using virtual circuits, we assume that the first server * is preferred over the rest (i.e. it is on the local diff --git a/StdLib/BsdSocketLib/write.c b/StdLib/BsdSocketLib/write.c index 1f8ad004b5..a6856b5616 100644 --- a/StdLib/BsdSocketLib/write.c +++ b/StdLib/BsdSocketLib/write.c @@ -28,6 +28,7 @@ **/ ssize_t +EFIAPI BslSocketWrite ( struct __filedes *pDescriptor, off_t * pOffset, diff --git a/StdLib/StdLib.dsc b/StdLib/StdLib.dsc index d01a2d6cb9..c352b22455 100644 --- a/StdLib/StdLib.dsc +++ b/StdLib/StdLib.dsc @@ -120,9 +120,9 @@ StdLib/PosixLib/Stringlist/LibStringlist.inf # Socket Libraries - LibC based -# StdLib/BsdSocketLib/BsdSocketLib.inf -# StdLib/EfiSocketLib/EfiSocketLib.inf -# StdLib/UseSocketDxe/UseSocketDxe.inf + StdLib/BsdSocketLib/BsdSocketLib.inf + StdLib/EfiSocketLib/EfiSocketLib.inf + StdLib/UseSocketDxe/UseSocketDxe.inf ############################################################################## #