mirror of
https://github.com/libretro/RetroArch.git
synced 2025-02-21 18:21:51 +00:00
Prevent implicit memsets
This commit is contained in:
parent
78a09be030
commit
481ebced22
@ -23,6 +23,7 @@
|
||||
#if __TEST_FNMATCH__
|
||||
#include <assert.h>
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
|
||||
#include <compat/fnmatch.h>
|
||||
|
||||
@ -34,9 +35,10 @@
|
||||
|
||||
int rl_fnmatch(const char *pattern, const char *string, int flags)
|
||||
{
|
||||
const char *c;
|
||||
int charmatch = 0;
|
||||
int rv;
|
||||
const char *c = NULL;
|
||||
int charmatch = 0;
|
||||
|
||||
for (c = pattern; *c != '\0'; c++)
|
||||
{
|
||||
/* String ended before pattern */
|
||||
|
@ -45,13 +45,12 @@ typedef struct NetlinkList
|
||||
|
||||
static int netlink_socket(void)
|
||||
{
|
||||
int l_socket = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
|
||||
if(l_socket < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct sockaddr_nl l_addr;
|
||||
int l_socket = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
|
||||
|
||||
if(l_socket < 0)
|
||||
return -1;
|
||||
|
||||
memset(&l_addr, 0, sizeof(l_addr));
|
||||
l_addr.nl_family = AF_NETLINK;
|
||||
if(bind(l_socket, (struct sockaddr *)&l_addr, sizeof(l_addr)) < 0)
|
||||
@ -70,6 +69,7 @@ static int netlink_send(int p_socket, int p_request)
|
||||
struct nlmsghdr m_hdr;
|
||||
struct rtgenmsg m_msg;
|
||||
} l_data;
|
||||
struct sockaddr_nl l_addr;
|
||||
|
||||
memset(&l_data, 0, sizeof(l_data));
|
||||
|
||||
@ -80,7 +80,6 @@ static int netlink_send(int p_socket, int p_request)
|
||||
l_data.m_hdr.nlmsg_seq = p_socket;
|
||||
l_data.m_msg.rtgen_family = AF_UNSPEC;
|
||||
|
||||
struct sockaddr_nl l_addr;
|
||||
memset(&l_addr, 0, sizeof(l_addr));
|
||||
l_addr.nl_family = AF_NETLINK;
|
||||
return (sendto(p_socket, &l_data.m_hdr, l_data.m_hdr.nlmsg_len, 0, (struct sockaddr *)&l_addr, sizeof(l_addr)));
|
||||
@ -106,16 +105,12 @@ static int netlink_recv(int p_socket, void *p_buffer, size_t p_len)
|
||||
if(l_result < 0)
|
||||
{
|
||||
if(errno == EINTR)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
if(l_msg.msg_flags & MSG_TRUNC)
|
||||
{ // buffer was too small
|
||||
if(l_msg.msg_flags & MSG_TRUNC) /* buffer too small */
|
||||
return -1;
|
||||
}
|
||||
return l_result;
|
||||
}
|
||||
}
|
||||
@ -130,17 +125,17 @@ static struct nlmsghdr *getNetlinkResponse(int p_socket, int *p_size, int *p_don
|
||||
free(l_buffer);
|
||||
l_buffer = malloc(l_size);
|
||||
if (l_buffer == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int l_read = netlink_recv(p_socket, l_buffer, l_size);
|
||||
*p_size = l_read;
|
||||
|
||||
if(l_read == -2)
|
||||
{
|
||||
free(l_buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(l_read >= 0)
|
||||
{
|
||||
pid_t l_pid = getpid();
|
||||
@ -148,9 +143,7 @@ static struct nlmsghdr *getNetlinkResponse(int p_socket, int *p_size, int *p_don
|
||||
for(l_hdr = (struct nlmsghdr *)l_buffer; NLMSG_OK(l_hdr, (unsigned int)l_read); l_hdr = (struct nlmsghdr *)NLMSG_NEXT(l_hdr, l_read))
|
||||
{
|
||||
if((pid_t)l_hdr->nlmsg_pid != l_pid || (int)l_hdr->nlmsg_seq != p_socket)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(l_hdr->nlmsg_type == NLMSG_DONE)
|
||||
{
|
||||
@ -175,9 +168,7 @@ static NetlinkList *newListItem(struct nlmsghdr *p_data, unsigned int p_size)
|
||||
{
|
||||
NetlinkList *l_item = malloc(sizeof(NetlinkList));
|
||||
if (l_item == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l_item->m_next = NULL;
|
||||
l_item->m_data = p_data;
|
||||
@ -200,9 +191,7 @@ static void freeResultList(NetlinkList *p_list)
|
||||
static NetlinkList *getResultList(int p_socket, int p_request)
|
||||
{
|
||||
if(netlink_send(p_socket, p_request) < 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NetlinkList *l_list = NULL;
|
||||
NetlinkList *l_end = NULL;
|
||||
@ -210,30 +199,27 @@ static NetlinkList *getResultList(int p_socket, int p_request)
|
||||
int l_done = 0;
|
||||
while(!l_done)
|
||||
{
|
||||
NetlinkList *l_item = NULL;
|
||||
struct nlmsghdr *l_hdr = getNetlinkResponse(p_socket, &l_size, &l_done);
|
||||
if(!l_hdr)
|
||||
{ // error
|
||||
freeResultList(l_list);
|
||||
return NULL;
|
||||
}
|
||||
goto error;
|
||||
|
||||
NetlinkList *l_item = newListItem(l_hdr, l_size);
|
||||
l_item = newListItem(l_hdr, l_size);
|
||||
if (!l_item)
|
||||
{
|
||||
freeResultList(l_list);
|
||||
return NULL;
|
||||
}
|
||||
goto error;
|
||||
|
||||
if(!l_list)
|
||||
{
|
||||
l_list = l_item;
|
||||
}
|
||||
else
|
||||
{
|
||||
l_end->m_next = l_item;
|
||||
}
|
||||
l_end = l_item;
|
||||
}
|
||||
|
||||
return l_list;
|
||||
|
||||
error:
|
||||
freeResultList(l_list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static size_t maxSize(size_t a, size_t b)
|
||||
@ -252,8 +238,10 @@ static size_t calcAddrLen(sa_family_t p_family, int p_dataSize)
|
||||
case AF_PACKET:
|
||||
return maxSize(sizeof(struct sockaddr_ll), offsetof(struct sockaddr_ll, sll_addr) + p_dataSize);
|
||||
default:
|
||||
return maxSize(sizeof(struct sockaddr), offsetof(struct sockaddr, sa_data) + p_dataSize);
|
||||
break;
|
||||
}
|
||||
|
||||
return maxSize(sizeof(struct sockaddr), offsetof(struct sockaddr, sa_data) + p_dataSize);
|
||||
}
|
||||
|
||||
static void makeSockaddr(sa_family_t p_family, struct sockaddr *p_dest, void *p_data, size_t p_size)
|
||||
@ -280,30 +268,26 @@ static void makeSockaddr(sa_family_t p_family, struct sockaddr *p_dest, void *p_
|
||||
static void addToEnd(struct ifaddrs **p_resultList, struct ifaddrs *p_entry)
|
||||
{
|
||||
if(!*p_resultList)
|
||||
{
|
||||
*p_resultList = p_entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct ifaddrs *l_cur = *p_resultList;
|
||||
while(l_cur->ifa_next)
|
||||
{
|
||||
l_cur = l_cur->ifa_next;
|
||||
}
|
||||
l_cur->ifa_next = p_entry;
|
||||
}
|
||||
}
|
||||
|
||||
static int interpretLink(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList)
|
||||
{
|
||||
struct ifaddrs *l_entry = NULL;
|
||||
struct rtattr *l_rta = NULL;
|
||||
struct ifinfomsg *l_info = (struct ifinfomsg *)NLMSG_DATA(p_hdr);
|
||||
|
||||
size_t l_nameSize = 0;
|
||||
size_t l_addrSize = 0;
|
||||
size_t l_dataSize = 0;
|
||||
|
||||
size_t l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifinfomsg));
|
||||
struct rtattr *l_rta;
|
||||
|
||||
for(l_rta = IFLA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize))
|
||||
{
|
||||
size_t l_rtaDataSize = RTA_PAYLOAD(l_rta);
|
||||
@ -324,11 +308,10 @@ static int interpretLink(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList)
|
||||
}
|
||||
}
|
||||
|
||||
struct ifaddrs *l_entry = malloc(sizeof(struct ifaddrs) + sizeof(int) + l_nameSize + l_addrSize + l_dataSize);
|
||||
l_entry = malloc(sizeof(struct ifaddrs) + sizeof(int) + l_nameSize + l_addrSize + l_dataSize);
|
||||
if (l_entry == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(l_entry, 0, sizeof(struct ifaddrs));
|
||||
l_entry->ifa_name = "";
|
||||
|
||||
@ -357,13 +340,9 @@ static int interpretLink(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList)
|
||||
((struct sockaddr_ll *)l_addr)->sll_ifindex = l_info->ifi_index;
|
||||
((struct sockaddr_ll *)l_addr)->sll_hatype = l_info->ifi_type;
|
||||
if(l_rta->rta_type == IFLA_ADDRESS)
|
||||
{
|
||||
l_entry->ifa_addr = (struct sockaddr *)l_addr;
|
||||
}
|
||||
else
|
||||
{
|
||||
l_entry->ifa_broadaddr = (struct sockaddr *)l_addr;
|
||||
}
|
||||
l_addr += NLMSG_ALIGN(l_addrLen);
|
||||
break;
|
||||
}
|
||||
@ -391,13 +370,12 @@ static struct ifaddrs *findInterface(int p_index, struct ifaddrs **p_links, int
|
||||
struct ifaddrs *l_cur = *p_links;
|
||||
while(l_cur && l_num < p_numLinks)
|
||||
{
|
||||
char *l_indexPtr = ((char *)l_cur) + sizeof(struct ifaddrs);
|
||||
int l_index;
|
||||
char *l_indexPtr = ((char *)l_cur) + sizeof(struct ifaddrs);
|
||||
|
||||
memcpy(&l_index, l_indexPtr, sizeof(int));
|
||||
if(l_index == p_index)
|
||||
{
|
||||
return l_cur;
|
||||
}
|
||||
|
||||
l_cur = l_cur->ifa_next;
|
||||
++l_num;
|
||||
@ -407,21 +385,18 @@ static struct ifaddrs *findInterface(int p_index, struct ifaddrs **p_links, int
|
||||
|
||||
static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList, int p_numLinks)
|
||||
{
|
||||
size_t l_nameSize = 0;
|
||||
size_t l_addrSize = 0;
|
||||
int l_addedNetmask = 0;
|
||||
struct ifaddrmsg *l_info = (struct ifaddrmsg *)NLMSG_DATA(p_hdr);
|
||||
struct ifaddrs *l_interface = findInterface(l_info->ifa_index, p_resultList, p_numLinks);
|
||||
|
||||
if(l_info->ifa_family == AF_PACKET)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t l_nameSize = 0;
|
||||
size_t l_addrSize = 0;
|
||||
|
||||
int l_addedNetmask = 0;
|
||||
|
||||
size_t l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifaddrmsg));
|
||||
struct rtattr *l_rta;
|
||||
|
||||
for(l_rta = IFA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize))
|
||||
{
|
||||
size_t l_rtaDataSize = RTA_PAYLOAD(l_rta);
|
||||
@ -431,7 +406,8 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList,
|
||||
case IFA_ADDRESS:
|
||||
case IFA_LOCAL:
|
||||
if((l_info->ifa_family == AF_INET || l_info->ifa_family == AF_INET6) && !l_addedNetmask)
|
||||
{ // make room for netmask
|
||||
{
|
||||
/* make room for netmask */
|
||||
l_addrSize += NLMSG_ALIGN(calcAddrLen(l_info->ifa_family, l_rtaDataSize));
|
||||
l_addedNetmask = 1;
|
||||
}
|
||||
@ -448,9 +424,8 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList,
|
||||
|
||||
struct ifaddrs *l_entry = malloc(sizeof(struct ifaddrs) + l_nameSize + l_addrSize);
|
||||
if (l_entry == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(l_entry, 0, sizeof(struct ifaddrs));
|
||||
l_entry->ifa_name = (l_interface ? l_interface->ifa_name : "");
|
||||
|
||||
@ -459,9 +434,7 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList,
|
||||
|
||||
l_entry->ifa_flags = l_info->ifa_flags;
|
||||
if(l_interface)
|
||||
{
|
||||
l_entry->ifa_flags |= l_interface->ifa_flags;
|
||||
}
|
||||
|
||||
l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifaddrmsg));
|
||||
for(l_rta = IFA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize))
|
||||
@ -479,34 +452,26 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList,
|
||||
if(l_info->ifa_family == AF_INET6)
|
||||
{
|
||||
if(IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)l_rtaData) || IN6_IS_ADDR_MC_LINKLOCAL((struct in6_addr *)l_rtaData))
|
||||
{
|
||||
((struct sockaddr_in6 *)l_addr)->sin6_scope_id = l_info->ifa_index;
|
||||
}
|
||||
}
|
||||
|
||||
if(l_rta->rta_type == IFA_ADDRESS)
|
||||
{ // apparently in a point-to-point network IFA_ADDRESS contains the dest address and IFA_LOCAL contains the local address
|
||||
{
|
||||
/* apparently in a point-to-point network IFA_ADDRESS
|
||||
* contains the dest address and IFA_LOCAL contains the local address */
|
||||
if(l_entry->ifa_addr)
|
||||
{
|
||||
l_entry->ifa_dstaddr = (struct sockaddr *)l_addr;
|
||||
}
|
||||
else
|
||||
{
|
||||
l_entry->ifa_addr = (struct sockaddr *)l_addr;
|
||||
}
|
||||
}
|
||||
else if(l_rta->rta_type == IFA_LOCAL)
|
||||
{
|
||||
if(l_entry->ifa_addr)
|
||||
{
|
||||
l_entry->ifa_dstaddr = l_entry->ifa_addr;
|
||||
}
|
||||
l_entry->ifa_addr = (struct sockaddr *)l_addr;
|
||||
}
|
||||
else
|
||||
{
|
||||
l_entry->ifa_broadaddr = (struct sockaddr *)l_addr;
|
||||
}
|
||||
l_addr += NLMSG_ALIGN(l_addrLen);
|
||||
break;
|
||||
}
|
||||
@ -520,22 +485,26 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList,
|
||||
}
|
||||
}
|
||||
|
||||
if(l_entry->ifa_addr && (l_entry->ifa_addr->sa_family == AF_INET || l_entry->ifa_addr->sa_family == AF_INET6))
|
||||
if(l_entry->ifa_addr &&
|
||||
( l_entry->ifa_addr->sa_family == AF_INET
|
||||
|| l_entry->ifa_addr->sa_family == AF_INET6))
|
||||
{
|
||||
unsigned l_maxPrefix = (l_entry->ifa_addr->sa_family == AF_INET ? 32 : 128);
|
||||
unsigned l_prefix = (l_info->ifa_prefixlen > l_maxPrefix ? l_maxPrefix : l_info->ifa_prefixlen);
|
||||
char l_mask[16] = {0};
|
||||
unsigned i;
|
||||
for(i=0; i<(l_prefix/8); ++i)
|
||||
{
|
||||
l_mask[i] = 0xff;
|
||||
}
|
||||
if(l_prefix % 8)
|
||||
{
|
||||
l_mask[i] = 0xff << (8 - (l_prefix % 8));
|
||||
}
|
||||
char l_mask[16];
|
||||
unsigned l_maxPrefix = (l_entry->ifa_addr->sa_family == AF_INET
|
||||
? 32 : 128);
|
||||
unsigned l_prefix = (l_info->ifa_prefixlen > l_maxPrefix
|
||||
? l_maxPrefix : l_info->ifa_prefixlen);
|
||||
|
||||
makeSockaddr(l_entry->ifa_addr->sa_family, (struct sockaddr *)l_addr, l_mask, l_maxPrefix / 8);
|
||||
l_mask[0] = '\0';
|
||||
|
||||
for(i=0; i<(l_prefix/8); ++i)
|
||||
l_mask[i] = 0xff;
|
||||
if(l_prefix % 8)
|
||||
l_mask[i] = 0xff << (8 - (l_prefix % 8));
|
||||
|
||||
makeSockaddr(l_entry->ifa_addr->sa_family,
|
||||
(struct sockaddr *)l_addr, l_mask, l_maxPrefix / 8);
|
||||
l_entry->ifa_netmask = (struct sockaddr *)l_addr;
|
||||
}
|
||||
|
||||
@ -543,32 +512,28 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int interpretLinks(int p_socket, NetlinkList *p_netlinkList, struct ifaddrs **p_resultList)
|
||||
static int interpretLinks(int p_socket, NetlinkList *p_netlinkList,
|
||||
struct ifaddrs **p_resultList)
|
||||
{
|
||||
int l_numLinks = 0;
|
||||
pid_t l_pid = getpid();
|
||||
for(; p_netlinkList; p_netlinkList = p_netlinkList->m_next)
|
||||
{
|
||||
struct nlmsghdr *l_hdr = NULL;
|
||||
unsigned int l_nlsize = p_netlinkList->m_size;
|
||||
struct nlmsghdr *l_hdr;
|
||||
|
||||
for(l_hdr = p_netlinkList->m_data; NLMSG_OK(l_hdr, l_nlsize); l_hdr = NLMSG_NEXT(l_hdr, l_nlsize))
|
||||
{
|
||||
if((pid_t)l_hdr->nlmsg_pid != l_pid || (int)l_hdr->nlmsg_seq != p_socket)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(l_hdr->nlmsg_type == NLMSG_DONE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if(l_hdr->nlmsg_type == RTM_NEWLINK)
|
||||
{
|
||||
if(interpretLink(l_hdr, p_resultList) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
++l_numLinks;
|
||||
}
|
||||
}
|
||||
@ -576,50 +541,44 @@ static int interpretLinks(int p_socket, NetlinkList *p_netlinkList, struct ifadd
|
||||
return l_numLinks;
|
||||
}
|
||||
|
||||
static int interpretAddrs(int p_socket, NetlinkList *p_netlinkList, struct ifaddrs **p_resultList, int p_numLinks)
|
||||
static int interpretAddrs(int p_socket, NetlinkList *p_netlinkList,
|
||||
struct ifaddrs **p_resultList, int p_numLinks)
|
||||
{
|
||||
pid_t l_pid = getpid();
|
||||
for(; p_netlinkList; p_netlinkList = p_netlinkList->m_next)
|
||||
{
|
||||
struct nlmsghdr *l_hdr = NULL;
|
||||
unsigned int l_nlsize = p_netlinkList->m_size;
|
||||
struct nlmsghdr *l_hdr;
|
||||
|
||||
for(l_hdr = p_netlinkList->m_data; NLMSG_OK(l_hdr, l_nlsize); l_hdr = NLMSG_NEXT(l_hdr, l_nlsize))
|
||||
{
|
||||
if((pid_t)l_hdr->nlmsg_pid != l_pid || (int)l_hdr->nlmsg_seq != p_socket)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(l_hdr->nlmsg_type == NLMSG_DONE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if(l_hdr->nlmsg_type == RTM_NEWADDR)
|
||||
{
|
||||
if (interpretAddr(l_hdr, p_resultList, p_numLinks) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getifaddrs(struct ifaddrs **ifap)
|
||||
{
|
||||
int l_socket = 0;
|
||||
int l_result = 0;
|
||||
if(!ifap)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
*ifap = NULL;
|
||||
|
||||
int l_socket = netlink_socket();
|
||||
l_socket = netlink_socket();
|
||||
if(l_socket < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
NetlinkList *l_linkResults = getResultList(l_socket, RTM_GETLINK);
|
||||
if(!l_linkResults)
|
||||
@ -636,12 +595,10 @@ int getifaddrs(struct ifaddrs **ifap)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int l_result = 0;
|
||||
int l_numLinks = interpretLinks(l_socket, l_linkResults, ifap);
|
||||
|
||||
if(l_numLinks == -1 || interpretAddrs(l_socket, l_addrResults, ifap, l_numLinks) == -1)
|
||||
{
|
||||
l_result = -1;
|
||||
}
|
||||
|
||||
freeResultList(l_linkResults);
|
||||
freeResultList(l_addrResults);
|
||||
@ -651,7 +608,8 @@ int getifaddrs(struct ifaddrs **ifap)
|
||||
|
||||
void freeifaddrs(struct ifaddrs *ifa)
|
||||
{
|
||||
struct ifaddrs *l_cur;
|
||||
struct ifaddrs *l_cur = NULL;
|
||||
|
||||
while(ifa)
|
||||
{
|
||||
l_cur = ifa;
|
||||
|
@ -43,10 +43,10 @@ static int casencmp(const char *a, const char *b, size_t n)
|
||||
|
||||
char *strcasestr_retro__(const char *haystack, const char *needle)
|
||||
{
|
||||
size_t i, hay_len, needle_len, search_off;
|
||||
size_t i, search_off;
|
||||
size_t hay_len = strlen(haystack);
|
||||
size_t needle_len = strlen(needle);
|
||||
|
||||
hay_len = strlen(haystack);
|
||||
needle_len = strlen(needle);
|
||||
if (needle_len > hay_len)
|
||||
return NULL;
|
||||
|
||||
|
@ -520,7 +520,7 @@ uint64_t cpu_features_get(void)
|
||||
{
|
||||
int flags[4];
|
||||
int vendor_shuffle[3];
|
||||
char vendor[13] = {0};
|
||||
char vendor[13];
|
||||
size_t len = 0;
|
||||
uint64_t cpu_flags = 0;
|
||||
uint64_t cpu = 0;
|
||||
@ -606,6 +606,8 @@ uint64_t cpu_features_get(void)
|
||||
vendor_shuffle[0] = flags[1];
|
||||
vendor_shuffle[1] = flags[3];
|
||||
vendor_shuffle[2] = flags[2];
|
||||
|
||||
vendor[0] = '\0';
|
||||
memcpy(vendor, vendor_shuffle, sizeof(vendor_shuffle));
|
||||
|
||||
/* printf("[CPUID]: Vendor: %s\n", vendor); */
|
||||
|
@ -139,7 +139,7 @@ static int sevenzip_file_read(
|
||||
for (i = 0; i < db.db.NumFiles; i++)
|
||||
{
|
||||
size_t len;
|
||||
char infile[PATH_MAX_LENGTH] = {0};
|
||||
char infile[PATH_MAX_LENGTH];
|
||||
size_t offset = 0;
|
||||
size_t outSizeProcessed = 0;
|
||||
const CSzFileItem *f = db.db.Files + i;
|
||||
@ -167,6 +167,8 @@ static int sevenzip_file_read(
|
||||
|
||||
SzArEx_GetFileNameUtf16(&db, i, temp);
|
||||
res = SZ_ERROR_FAIL;
|
||||
infile[0] = '\0';
|
||||
|
||||
if (temp)
|
||||
res = utf16_to_char_string(temp, infile, sizeof(infile))
|
||||
? SZ_OK : SZ_ERROR_FAIL;
|
||||
@ -340,13 +342,15 @@ static int sevenzip_parse_file_iterate_step_internal(
|
||||
|
||||
if (len < PATH_MAX_LENGTH && !file->IsDir)
|
||||
{
|
||||
char infile[PATH_MAX_LENGTH];
|
||||
SRes res = SZ_ERROR_FAIL;
|
||||
char infile[PATH_MAX_LENGTH] = {0};
|
||||
uint16_t *temp = (uint16_t*)malloc(len * sizeof(uint16_t));
|
||||
|
||||
if (!temp)
|
||||
return -1;
|
||||
|
||||
infile[0] = '\0';
|
||||
|
||||
SzArEx_GetFileNameUtf16(&sevenzip_context->db, sevenzip_context->index,
|
||||
temp);
|
||||
|
||||
@ -375,8 +379,10 @@ static int sevenzip_parse_file_iterate_step_internal(
|
||||
}
|
||||
|
||||
static int sevenzip_parse_file_iterate_step(file_archive_transfer_t *state,
|
||||
const char *valid_exts, struct archive_extract_userdata *userdata, file_archive_file_cb file_cb)
|
||||
const char *valid_exts,
|
||||
struct archive_extract_userdata *userdata, file_archive_file_cb file_cb)
|
||||
{
|
||||
char filename[PATH_MAX_LENGTH];
|
||||
const uint8_t *cdata = NULL;
|
||||
uint32_t checksum = 0;
|
||||
uint32_t size = 0;
|
||||
@ -384,7 +390,6 @@ static int sevenzip_parse_file_iterate_step(file_archive_transfer_t *state,
|
||||
unsigned cmode = 0;
|
||||
unsigned payload = 0;
|
||||
struct sevenzip_context_t *sevenzip_context = NULL;
|
||||
char filename[PATH_MAX_LENGTH] = {0};
|
||||
int ret = sevenzip_parse_file_iterate_step_internal(state, filename,
|
||||
&cdata, &cmode, &size, &csize,
|
||||
&checksum, &payload, userdata);
|
||||
@ -392,6 +397,7 @@ static int sevenzip_parse_file_iterate_step(file_archive_transfer_t *state,
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
|
||||
filename[0] = '\0';
|
||||
userdata->extracted_file_path = filename;
|
||||
userdata->crc = checksum;
|
||||
|
||||
|
@ -258,7 +258,7 @@ static void add_child_list(config_file_t *parent, config_file_t *child)
|
||||
|
||||
static void add_sub_conf(config_file_t *conf, char *line)
|
||||
{
|
||||
char real_path[PATH_MAX_LENGTH] = {0};
|
||||
char real_path[PATH_MAX_LENGTH];
|
||||
config_file_t *sub_conf = NULL;
|
||||
char *path = extract_value(line, false);
|
||||
|
||||
@ -267,6 +267,8 @@ static void add_sub_conf(config_file_t *conf, char *line)
|
||||
|
||||
add_include_list(conf, path);
|
||||
|
||||
real_path[0] = '\0';
|
||||
|
||||
#ifdef _WIN32
|
||||
fill_pathname_resolve_relative(real_path, conf->path,
|
||||
path, sizeof(real_path));
|
||||
@ -802,7 +804,9 @@ void config_set_path(config_file_t *conf, const char *entry, const char *val)
|
||||
#if defined(RARCH_CONSOLE)
|
||||
config_set_string(conf, entry, val);
|
||||
#else
|
||||
char buf[PATH_MAX_LENGTH] = {0};
|
||||
char buf[PATH_MAX_LENGTH];
|
||||
|
||||
buf[0] = '\0';
|
||||
fill_pathname_abbreviate_special(buf, val, sizeof(buf));
|
||||
config_set_string(conf, entry, buf);
|
||||
#endif
|
||||
@ -810,7 +814,9 @@ void config_set_path(config_file_t *conf, const char *entry, const char *val)
|
||||
|
||||
void config_set_double(config_file_t *conf, const char *key, double val)
|
||||
{
|
||||
char buf[128] = {0};
|
||||
char buf[128];
|
||||
|
||||
buf[0] = '\0';
|
||||
#ifdef __cplusplus
|
||||
snprintf(buf, sizeof(buf), "%f", (float)val);
|
||||
#elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
|
||||
@ -823,28 +829,36 @@ void config_set_double(config_file_t *conf, const char *key, double val)
|
||||
|
||||
void config_set_float(config_file_t *conf, const char *key, float val)
|
||||
{
|
||||
char buf[128] = {0};
|
||||
char buf[128];
|
||||
|
||||
buf[0] = '\0';
|
||||
snprintf(buf, sizeof(buf), "%f", val);
|
||||
config_set_string(conf, key, buf);
|
||||
}
|
||||
|
||||
void config_set_int(config_file_t *conf, const char *key, int val)
|
||||
{
|
||||
char buf[128] = {0};
|
||||
char buf[128];
|
||||
|
||||
buf[0] = '\0';
|
||||
snprintf(buf, sizeof(buf), "%d", val);
|
||||
config_set_string(conf, key, buf);
|
||||
}
|
||||
|
||||
void config_set_hex(config_file_t *conf, const char *key, unsigned val)
|
||||
{
|
||||
char buf[128] = {0};
|
||||
char buf[128];
|
||||
|
||||
buf[0] = '\0';
|
||||
snprintf(buf, sizeof(buf), "%x", val);
|
||||
config_set_string(conf, key, buf);
|
||||
}
|
||||
|
||||
void config_set_uint64(config_file_t *conf, const char *key, uint64_t val)
|
||||
{
|
||||
char buf[128] = {0};
|
||||
char buf[128];
|
||||
|
||||
buf[0] = '\0';
|
||||
#ifdef _WIN32
|
||||
snprintf(buf, sizeof(buf), "%I64u", val);
|
||||
#else
|
||||
@ -855,7 +869,9 @@ void config_set_uint64(config_file_t *conf, const char *key, uint64_t val)
|
||||
|
||||
void config_set_char(config_file_t *conf, const char *key, char val)
|
||||
{
|
||||
char buf[2] = {0};
|
||||
char buf[2];
|
||||
|
||||
buf[0] = '\0';
|
||||
snprintf(buf, sizeof(buf), "%c", val);
|
||||
config_set_string(conf, key, buf);
|
||||
}
|
||||
|
@ -467,9 +467,11 @@ void fill_dated_filename(char *out_filename,
|
||||
void fill_str_dated_filename(char *out_filename,
|
||||
const char *in_str, const char *ext, size_t size)
|
||||
{
|
||||
char format[256] = {0};
|
||||
char format[256];
|
||||
time_t cur_time = time(NULL);
|
||||
|
||||
format[0] = '\0';
|
||||
|
||||
strftime(format, sizeof(format), "-%y%m%d-%H%M%S.", localtime(&cur_time));
|
||||
strlcpy(out_filename, in_str, size);
|
||||
strlcat(out_filename, format, size);
|
||||
|
@ -508,14 +508,16 @@ static void SHA1Input(SHA1Context *context,
|
||||
|
||||
int sha1_calculate(const char *path, char *result)
|
||||
{
|
||||
unsigned char buff[4096] = {0};
|
||||
SHA1Context sha;
|
||||
unsigned char buff[4096];
|
||||
int rv = 1;
|
||||
RFILE *fd = filestream_open(path, RFILE_MODE_READ, -1);
|
||||
|
||||
if (!fd)
|
||||
goto error;
|
||||
|
||||
buff[0] = '\0';
|
||||
|
||||
SHA1Reset(&sha);
|
||||
|
||||
do
|
||||
|
@ -437,7 +437,7 @@ void file_list_get_last(const file_list_t *list,
|
||||
bool file_list_search(const file_list_t *list, const char *needle, size_t *idx)
|
||||
{
|
||||
size_t i;
|
||||
const char *alt;
|
||||
const char *alt = NULL;
|
||||
bool ret = false;
|
||||
|
||||
if (!list)
|
||||
@ -445,7 +445,8 @@ bool file_list_search(const file_list_t *list, const char *needle, size_t *idx)
|
||||
|
||||
for (i = 0; i < list->size; i++)
|
||||
{
|
||||
const char *str;
|
||||
const char *str = NULL;
|
||||
|
||||
file_list_get_alt_at_offset(list, i, &alt);
|
||||
if (!alt)
|
||||
{
|
||||
|
@ -290,11 +290,13 @@ bool string_list_find_elem_prefix(const struct string_list *list,
|
||||
const char *prefix, const char *elem)
|
||||
{
|
||||
size_t i;
|
||||
char prefixed[PATH_MAX_LENGTH] = {0};
|
||||
char prefixed[PATH_MAX_LENGTH];
|
||||
|
||||
if (!list)
|
||||
return false;
|
||||
|
||||
prefixed[0] = '\0';
|
||||
|
||||
strlcpy(prefixed, prefix, sizeof(prefixed));
|
||||
strlcat(prefixed, elem, sizeof(prefixed));
|
||||
|
||||
|
@ -254,7 +254,9 @@ struct http_t *net_http_new(struct http_connection_t *conn)
|
||||
|
||||
if (conn->port != 80)
|
||||
{
|
||||
char portstr[16] = {0};
|
||||
char portstr[16];
|
||||
|
||||
portstr[0] = '\0';
|
||||
|
||||
snprintf(portstr, sizeof(portstr), ":%i", conn->port);
|
||||
net_http_send_str(fd, &error, portstr);
|
||||
|
@ -62,6 +62,8 @@ static void task_queue_msg_push(unsigned prio, unsigned duration,
|
||||
char buf[1024];
|
||||
va_list ap;
|
||||
|
||||
buf[0] = '\0';
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||
va_end(ap);
|
||||
|
@ -79,9 +79,10 @@ char *string_replace_substring(const char *in,
|
||||
const char *pattern, const char *replacement)
|
||||
{
|
||||
size_t numhits, pattern_len, replacement_len, outlen;
|
||||
const char *inat;
|
||||
const char *inprev;
|
||||
char *out, *outat;
|
||||
const char *inat = NULL;
|
||||
const char *inprev = NULL;
|
||||
char *out = NULL;
|
||||
char *outat = NULL;
|
||||
|
||||
/* if either pattern or replacement is NULL,
|
||||
* duplicate in and let caller handle it. */
|
||||
|
@ -356,8 +356,8 @@ static bool load_content_from_compressed_archive(
|
||||
bool need_fullpath, const char *path)
|
||||
{
|
||||
union string_list_elem_attr attributes;
|
||||
char new_path[PATH_MAX_LENGTH] = {0};
|
||||
char new_basedir[PATH_MAX_LENGTH] = {0};
|
||||
char new_path[PATH_MAX_LENGTH];
|
||||
char new_basedir[PATH_MAX_LENGTH];
|
||||
ssize_t new_path_len = 0;
|
||||
bool ret = false;
|
||||
rarch_system_info_t *sys_info= NULL;
|
||||
@ -386,7 +386,10 @@ static bool load_content_from_compressed_archive(
|
||||
sizeof(new_basedir));
|
||||
}
|
||||
|
||||
new_path[0] = '\0';
|
||||
new_basedir[0] = '\0';
|
||||
attributes.i = 0;
|
||||
|
||||
fill_pathname_join(new_path, new_basedir,
|
||||
path_basename(path), sizeof(new_path));
|
||||
|
||||
@ -425,8 +428,8 @@ static bool init_content_file_extract(
|
||||
|
||||
for (i = 0; i < content->size; i++)
|
||||
{
|
||||
char temp_content[PATH_MAX_LENGTH] = {0};
|
||||
char new_path[PATH_MAX_LENGTH] = {0};
|
||||
char temp_content[PATH_MAX_LENGTH];
|
||||
char new_path[PATH_MAX_LENGTH];
|
||||
bool contains_compressed = NULL;
|
||||
bool block_extract = content->elems[i].attr.i & 1;
|
||||
const char *valid_ext = system->info.valid_extensions;
|
||||
@ -447,6 +450,8 @@ static bool init_content_file_extract(
|
||||
continue;
|
||||
}
|
||||
|
||||
temp_content[0] = new_path[0] = '\0';
|
||||
|
||||
strlcpy(temp_content, content->elems[i].data,
|
||||
sizeof(temp_content));
|
||||
|
||||
@ -867,8 +872,10 @@ static bool task_load_content(content_ctx_info_t *content_info,
|
||||
bool launched_from_menu,
|
||||
enum content_mode_load mode)
|
||||
{
|
||||
char name[PATH_MAX_LENGTH] = {0};
|
||||
char msg[PATH_MAX_LENGTH] = {0};
|
||||
char name[PATH_MAX_LENGTH];
|
||||
char msg[PATH_MAX_LENGTH];
|
||||
|
||||
name[0] = msg[0] = '\0';
|
||||
|
||||
if (launched_from_menu)
|
||||
{
|
||||
@ -897,10 +904,12 @@ static bool task_load_content(content_ctx_info_t *content_info,
|
||||
/* Push entry to top of history playlist */
|
||||
if (content_is_inited() || content_does_not_need_content())
|
||||
{
|
||||
char tmp[PATH_MAX_LENGTH] = {0};
|
||||
char tmp[PATH_MAX_LENGTH];
|
||||
struct retro_system_info *info = NULL;
|
||||
rarch_system_info_t *system = NULL;
|
||||
|
||||
tmp[0] = '\0';
|
||||
|
||||
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system);
|
||||
if (system)
|
||||
info = &system->info;
|
||||
|
@ -51,7 +51,9 @@ typedef struct db_handle
|
||||
static int task_database_iterate_start(database_info_handle_t *db,
|
||||
const char *name)
|
||||
{
|
||||
char msg[128] = {0};
|
||||
char msg[128];
|
||||
|
||||
msg[0] = '\0';
|
||||
|
||||
snprintf(msg, sizeof(msg),
|
||||
STRING_REP_ULONG "/" STRING_REP_ULONG ": %s %s...\n",
|
||||
@ -107,9 +109,13 @@ static int iso_get_serial(database_state_handle_t *db_state,
|
||||
static int cue_get_serial(database_state_handle_t *db_state,
|
||||
database_info_handle_t *db, const char *name, char* serial)
|
||||
{
|
||||
char track_path[PATH_MAX_LENGTH];
|
||||
int32_t offset = 0;
|
||||
char track_path[PATH_MAX_LENGTH] = {0};
|
||||
int rv = find_first_data_track(name,
|
||||
int rv = 0;
|
||||
|
||||
track_path[0] = '\0';
|
||||
|
||||
rv = find_first_data_track(name,
|
||||
&offset, track_path, PATH_MAX_LENGTH);
|
||||
|
||||
if (rv < 0)
|
||||
@ -329,7 +335,9 @@ static int task_database_iterate_crc_lookup(
|
||||
|
||||
if (db_state->entry_index == 0)
|
||||
{
|
||||
char query[50] = {0};
|
||||
char query[50];
|
||||
|
||||
query[0] = '\0';
|
||||
|
||||
if (!core_info_database_supports_content_path(db_state->list->elems[db_state->list_index].data, name) &&
|
||||
!core_info_unsupported_content_path(name))
|
||||
@ -450,13 +458,15 @@ static int task_database_iterate_serial_lookup(
|
||||
|
||||
if (db_state->entry_index == 0)
|
||||
{
|
||||
char query[50] = {0};
|
||||
char query[50];
|
||||
char *serial_buf =
|
||||
bin_to_hex_alloc((uint8_t*)db_state->serial, 10 * sizeof(uint8_t));
|
||||
|
||||
if (!serial_buf)
|
||||
return 1;
|
||||
|
||||
query[0] = '\0';
|
||||
|
||||
snprintf(query, sizeof(query), "{'serial': b'%s'}", serial_buf);
|
||||
database_info_list_iterate_new(db_state, query);
|
||||
|
||||
|
@ -382,7 +382,7 @@ int find_first_data_track(const char *cue_path,
|
||||
int32_t *offset, char *track_path, size_t max_len)
|
||||
{
|
||||
int rv;
|
||||
char tmp_token[MAX_TOKEN_LEN] = {0};
|
||||
char tmp_token[MAX_TOKEN_LEN];
|
||||
RFILE *fd =
|
||||
filestream_open(cue_path, RFILE_MODE_READ, -1);
|
||||
|
||||
@ -395,6 +395,8 @@ int find_first_data_track(const char *cue_path,
|
||||
|
||||
RARCH_LOG("Parsing CUE file '%s'...\n", cue_path);
|
||||
|
||||
tmp_token[0] = '\0';
|
||||
|
||||
while (get_token(fd, tmp_token, MAX_TOKEN_LEN) > 0)
|
||||
{
|
||||
if (string_is_equal(tmp_token, "FILE"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user