- eliminate use of alloca() and strdupa().

- don't include malloc.h
- fix compile warnings
This commit is contained in:
David Anderson 2012-12-26 11:25:16 -08:00 committed by Oliver Bock
parent 7735ee4410
commit 13f1257355
5 changed files with 41 additions and 65 deletions

View File

@ -7907,3 +7907,17 @@ Charlie 26 Dec 2012
BOINCInternetFSHandler.cpp,.h BOINCInternetFSHandler.cpp,.h
NoticeListCtrl.cpp NoticeListCtrl.cpp
sg_DlgMessages.cpp,.h sg_DlgMessages.cpp,.h
David 27 Dec 2012
- eliminate use of alloca() and strdupa().
- don't include malloc.h
- fix compile warnings
configure.ac
clientscr/
screensaver_x11.cpp
lib/
str_util.cpp
sched/
hr_info.cpp

View File

@ -21,7 +21,7 @@
// To use this screensaver, please add the following to the 'programs' // To use this screensaver, please add the following to the 'programs'
// preference in your .xscreensaver file: // preference in your .xscreensaver file:
// //
// GL: boincscr -root \n\ // GL: "boincscr -root \n\"
// //
// If your BOINC directory differs from /var/lib/boinc-client, you can use // If your BOINC directory differs from /var/lib/boinc-client, you can use
// the -boinc_dir command line argument. // the -boinc_dir command line argument.
@ -169,10 +169,9 @@ public:
mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
values[0] = scr->black_pixel; values[0] = scr->black_pixel;
values[1] = XCB_EVENT_MASK_EXPOSURE; values[1] = XCB_EVENT_MASK_EXPOSURE;
xcb_void_cookie_t cookie = cookie = xcb_change_window_attributes(con, win, mask, values);
xcb_change_window_attributes(con, win, mask, values);
xcb_generic_error_t *error = xcb_request_check(con, cookie); error = xcb_request_check(con, cookie);
if(error) { if(error) {
std::cerr << "Could not configure window." << std::endl; std::cerr << "Could not configure window." << std::endl;
exit(1); exit(1);
@ -419,7 +418,7 @@ int main(int argc, char *argv[]) {
} }
// get default screen // get default screen
xcb_screen_t *screen; xcb_screen_t *screen = NULL;
for(xcb_screen_iterator_t it = xcb_setup_roots_iterator(xcb_get_setup(con)); for(xcb_screen_iterator_t it = xcb_setup_roots_iterator(xcb_get_setup(con));
it.rem; screen_num--, xcb_screen_next(&it)) it.rem; screen_num--, xcb_screen_next(&it))
if(!screen_num) screen = it.data; if(!screen_num) screen = it.data;
@ -515,7 +514,7 @@ int main(int argc, char *argv[]) {
static_cast<xcb_window_t*>(xcb_get_property_value(reply)); static_cast<xcb_window_t*>(xcb_get_property_value(reply));
// check if one of them is our graphics app // check if one of them is our graphics app
for(int c = 0; c < reply->length; c++) { for(unsigned int c = 0; c < reply->length; c++) {
xcb_get_property_reply_t *reply2; xcb_get_property_reply_t *reply2;
// check WM_COMMAND // check WM_COMMAND

View File

@ -611,7 +611,7 @@ AC_HEADER_STDC
AC_HEADER_SYS_WAIT AC_HEADER_SYS_WAIT
AC_HEADER_TIME AC_HEADER_TIME
AC_TYPE_SIGNAL AC_TYPE_SIGNAL
AC_CHECK_HEADERS(windows.h sys/types.h sys/un.h arpa/inet.h dirent.h grp.h fcntl.h inttypes.h stdint.h malloc.h alloca.h memory.h netdb.h netinet/in.h netinet/tcp.h netinet/ether.h signal.h strings.h sys/auxv.h sys/file.h sys/fcntl.h sys/ipc.h sys/ioctl.h sys/msg.h sys/param.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/sockio.h sys/socket.h sys/stat.h sys/statvfs.h sys/statfs.h sys/systeminfo.h sys/time.h sys/types.h sys/utsname.h sys/vmmeter.h sys/wait.h unistd.h utmp.h errno.h procfs.h ieeefp.h setjmp.h) AC_CHECK_HEADERS(windows.h sys/types.h sys/un.h arpa/inet.h dirent.h grp.h fcntl.h inttypes.h stdint.h memory.h netdb.h netinet/in.h netinet/tcp.h netinet/ether.h signal.h strings.h sys/auxv.h sys/file.h sys/fcntl.h sys/ipc.h sys/ioctl.h sys/msg.h sys/param.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/sockio.h sys/socket.h sys/stat.h sys/statvfs.h sys/statfs.h sys/systeminfo.h sys/time.h sys/types.h sys/utsname.h sys/vmmeter.h sys/wait.h unistd.h utmp.h errno.h procfs.h ieeefp.h setjmp.h)
AC_CHECK_HEADER(net/if.h, [], [], [[ AC_CHECK_HEADER(net/if.h, [], [], [[
#if HAVE_SYS_SOCKET_H #if HAVE_SYS_SOCKET_H
@ -703,11 +703,7 @@ AC_LANG_POP
dnl Checks for library functions. dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL AC_PROG_GCC_TRADITIONAL
AC_FUNC_VPRINTF AC_FUNC_VPRINTF
AC_FUNC_ALLOCA AC_CHECK_FUNCS(ether_ntoa setpriority sched_setscheduler strlcpy strlcat strcasestr strcasecmp sigaction getutent setutent getisax strdup strdupa daemon stat64 putenv setenv unsetenv res_init strtoull)
if test "${ac_cv_func_alloca_works}" = "yes" ; then
ac_cv_func_alloca="yes"
fi
AC_CHECK_FUNCS(alloca _alloca __builtin_alloca ether_ntoa setpriority sched_setscheduler strlcpy strlcat strcasestr strcasecmp sigaction getutent setutent getisax strdup strdupa daemon stat64 putenv setenv unsetenv res_init strtoull)
dnl Checks for typedefs, structures, and compiler characteristics. dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST AC_C_CONST

View File

@ -31,9 +31,6 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#if HAVE_ALLOCA_H
#include "alloca.h"
#endif
#endif #endif
#ifdef _USING_FCGI_ #ifdef _USING_FCGI_
@ -83,56 +80,29 @@ size_t strlcat(char *dst, const char *src, size_t size) {
#endif // !HAVE_STRLCAT #endif // !HAVE_STRLCAT
#if !HAVE_STRCASESTR #if !HAVE_STRCASESTR
// BOINC only uses strcasestr() for short strings,
// so the following till suffice
//
const char *strcasestr(const char *s1, const char *s2) { const char *strcasestr(const char *s1, const char *s2) {
char *needle=NULL, *haystack=NULL, *p=NULL; char needle[1024], haystack[1024], *p=NULL;
bool need_free = false; strlcpy(haystack, s1, sizeof(haystack));
// Is alloca() really less likely to fail with out of memory error strlcpy(needle, s2, sizeof(needle));
// than strdup? // convert both strings to lower case
#if HAVE_STRDUPA p = haystack;
haystack=strdupa(s1); while (*p) {
needle=strdupa(s2); *p = tolower(*p);
#elif HAVE_ALLOCA_H || HAVE_ALLOCA p++;
haystack=(char *)alloca(strlen(s1)+1);
needle=(char *)alloca(strlen(s2)+1);
if (needle && haystack) {
strlcpy(haystack,s1,strlen(s1)+1);
strlcpy(needle,s2,strlen(s2)+1);
} }
#elif HAVE_STRDUP p = needle;
haystack=strdup(s1); while (*p) {
needle=strdup(s1) *p = tolower(*p);
need_free = true; p++;
#else
haystack=(char *)malloc(strlen(s1)+1);
needle=(char *)malloc(strlen(s2)+1);
if (needle && haystack) {
strlcpy(haystack,s1,strlen(s1)+1);
strlcpy(needle,s2,strlen(s2)+1);
} }
need_free = true; // find the substring
#endif p = strstr(haystack, needle);
if (needle && haystack) { // correct the pointer to point to the substring within s1
// convert both strings to lower case if (p) {
p = haystack; p = const_cast<char *>(s1)+(p-haystack);
while (*p) {
*p = tolower(*p);
p++;
}
p = needle;
while (*p) {
*p = tolower(*p);
p++;
}
// find the substring
p = strstr(haystack, needle);
// correct the pointer to point to the substring within s1
if (p) {
p = const_cast<char *>(s1)+(p-haystack);
}
}
if (need_free) {
if (needle) free(needle);
if (haystack) free(haystack);
} }
return p; return p;
} }

View File

@ -22,9 +22,6 @@
#else #else
#include "boinc_fcgi.h" #include "boinc_fcgi.h"
#endif #endif
#if HAVE_MALLOC_H
#include <malloc.h>
#endif
#include <cmath> #include <cmath>
#include "error_numbers.h" #include "error_numbers.h"