comparison src/loadso/macosx/SDL_sysloadso.c @ 1379:c0a74f199ecf

Use only safe string functions
author Sam Lantinga <slouken@libsdl.org>
date Sun, 19 Feb 2006 23:46:34 +0000
parents 3793c4b34a92
children d910939febfa
comparison
equal deleted inserted replaced
1378:dc0e13e7e1ae 1379:c0a74f199ecf
279 struct dlthread *tss; 279 struct dlthread *tss;
280 char * err_str; 280 char * err_str;
281 va_start(arg, str); 281 va_start(arg, str);
282 tss = pthread_getspecific(dlerror_key); 282 tss = pthread_getspecific(dlerror_key);
283 err_str = tss->errstr; 283 err_str = tss->errstr;
284 SDL_strncpy(err_str, "dlcompat: ", ERR_STR_LEN); 284 SDL_strlcpy(err_str, "dlcompat: ", ERR_STR_LEN);
285 vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg); 285 vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg);
286 va_end(arg); 286 va_end(arg);
287 debug("ERROR: %s\n", err_str); 287 debug("ERROR: %s\n", err_str);
288 tss->errset = 1; 288 tss->errset = 1;
289 } 289 }
618 } 618 }
619 return nssym; 619 return nssym;
620 } 620 }
621 621
622 /* Up to the caller to SDL_free() returned string */ 622 /* Up to the caller to SDL_free() returned string */
623 static inline const char *dyld_error_str() 623 static inline char *dyld_error_str()
624 { 624 {
625 NSLinkEditErrors dylder; 625 NSLinkEditErrors dylder;
626 int dylderno; 626 int dylderno;
627 const char *dylderrstr; 627 const char *dylderrstr;
628 const char *dyldfile; 628 const char *dyldfile;
629 const char* retStr = NULL; 629 char* retStr = NULL;
630 NSLinkEditError(&dylder, &dylderno, &dyldfile, &dylderrstr); 630 NSLinkEditError(&dylder, &dylderno, &dyldfile, &dylderrstr);
631 if (dylderrstr && SDL_strlen(dylderrstr)) 631 if (dylderrstr && *dylderrstr)
632 { 632 {
633 retStr = SDL_malloc(SDL_strlen(dylderrstr) +1); 633 retStr = SDL_strdup(dylderrstr);
634 SDL_strcpy((char*)retStr,dylderrstr);
635 } 634 }
636 return retStr; 635 return retStr;
637 } 636 }
638 637
639 static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError) 638 static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError)
643 void *caller = __builtin_return_address(1); /* Be *very* careful about inlining */ 642 void *caller = __builtin_return_address(1); /* Be *very* careful about inlining */
644 #else 643 #else
645 void *caller = NULL; 644 void *caller = NULL;
646 #endif 645 #endif
647 const struct mach_header *caller_mh = 0; 646 const struct mach_header *caller_mh = 0;
648 const char* savedErrorStr = NULL; 647 char* savedErrorStr = NULL;
649 resetdlerror(); 648 resetdlerror();
650 #ifndef RTLD_SELF 649 #ifndef RTLD_SELF
651 #define RTLD_SELF ((void *) -3) 650 #define RTLD_SELF ((void *) -3)
652 #endif 651 #endif
653 if (NULL == dls) 652 if (NULL == dls)
732 nssym = NSLookupAndBindSymbol(symbol); 731 nssym = NSLookupAndBindSymbol(symbol);
733 } 732 }
734 else 733 else
735 { 734 {
736 if (savedErrorStr) 735 if (savedErrorStr)
737 SDL_free((char*)savedErrorStr); 736 SDL_free(savedErrorStr);
738 savedErrorStr = SDL_malloc(256); 737 savedErrorStr = SDL_malloc(256);
739 SDL_snprintf((char*)savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol); 738 SDL_snprintf(savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol);
740 } 739 }
741 } 740 }
742 } 741 }
743 /* Error reporting */ 742 /* Error reporting */
744 if (!nssym) 743 if (!nssym)
745 { 744 {
746 if (!savedErrorStr || !SDL_strlen(savedErrorStr)) 745 if (!savedErrorStr || !SDL_strlen(savedErrorStr))
747 { 746 {
748 if (savedErrorStr) 747 if (savedErrorStr)
749 SDL_free((char*)savedErrorStr); 748 SDL_free(savedErrorStr);
750 savedErrorStr = SDL_malloc(256); 749 savedErrorStr = SDL_malloc(256);
751 SDL_snprintf((char*)savedErrorStr, 256,"Symbol \"%s\" not found",symbol); 750 SDL_snprintf(savedErrorStr, 256,"Symbol \"%s\" not found",symbol);
752 } 751 }
753 if (canSetError) 752 if (canSetError)
754 { 753 {
755 error(savedErrorStr); 754 error(savedErrorStr);
756 } 755 }
757 else 756 else
758 { 757 {
759 debug(savedErrorStr); 758 debug(savedErrorStr);
760 } 759 }
761 if (savedErrorStr) 760 if (savedErrorStr)
762 SDL_free((char*)savedErrorStr); 761 SDL_free(savedErrorStr);
763 return NULL; 762 return NULL;
764 } 763 }
765 return NSAddressOfSymbol(nssym); 764 return NSAddressOfSymbol(nssym);
766 } 765 }
767 766