Remove a few more instances of strncpy.

This commit is contained in:
Alexandre Julliard 2005-04-25 15:51:45 +00:00
parent 172e731c0b
commit 240d4ee9e1
7 changed files with 88 additions and 49 deletions

View File

@ -223,22 +223,29 @@ void _mbccpy(unsigned char* dest, const unsigned char* src)
*/
unsigned char* _mbsncpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
{
unsigned char* ret = dst;
if(!n)
return dst;
if(MSVCRT___mb_cur_max > 1)
{
unsigned char* ret = dst;
while (*src && n--)
while (*src && n)
{
n--;
*dst++ = *src;
if (MSVCRT_isleadbyte(*src++))
*dst++ = *src++;
}
while(n--)
*dst++ = '\0';
return ret;
}
return strncpy(dst, src, n); /* ASCII CP */
else
{
while (n)
{
n--;
if (!(*dst++ = *src++)) break;
}
}
while (n--) *dst++ = 0;
return ret;
}
/*********************************************************************
@ -246,13 +253,14 @@ unsigned char* _mbsncpy(unsigned char* dst, const unsigned char* src, MSVCRT_siz
*/
unsigned char* _mbsnbcpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
{
unsigned char* ret = dst;
if(!n)
return dst;
if(MSVCRT___mb_cur_max > 1)
{
unsigned char* ret = dst;
while (*src && (n-- > 1))
while (*src && (n > 1))
{
n--;
*dst++ = *src;
if (MSVCRT_isleadbyte(*src++))
{
@ -268,11 +276,17 @@ unsigned char* _mbsnbcpy(unsigned char* dst, const unsigned char* src, MSVCRT_si
*dst++ = *src;
n--;
}
while (n--)
*dst++ = '\0';
return ret;
}
return strncpy(dst, src, n); /* ASCII CP */
else
{
while (n)
{
n--;
if (!(*dst++ = *src++)) break;
}
}
while (n--) *dst++ = 0;
return ret;
}
/*********************************************************************

View File

@ -1515,9 +1515,9 @@ NTSTATUS WINAPI NtQueryVolumeInformationFile( HANDLE handle, PIO_STATUS_BLOCK io
mach_port_t masterPort;
char bsdName[6]; /* disk#\0 */
strncpy(bsdName, stfs.f_mntfromname+strlen(_PATH_DEV) , 5);
bsdName[5] = 0;
const char *name = stfs.f_mntfromname + strlen(_PATH_DEV);
memcpy( bsdName, name, min(strlen(name)+1,sizeof(bsdName)) );
bsdName[sizeof(bsdName)-1] = 0;
kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);

View File

@ -39,9 +39,9 @@ extern void wine_exec_wine_binary( const char *name, char **argv, char **envp, i
typedef void (*load_dll_callback_t)( void *, const char * );
extern void *wine_dlopen( const char *filename, int flag, char *error, int errorsize );
extern void *wine_dlsym( void *handle, const char *symbol, char *error, int errorsize );
extern int wine_dlclose( void *handle, char *error, int errorsize );
extern void *wine_dlopen( const char *filename, int flag, char *error, size_t errorsize );
extern void *wine_dlsym( void *handle, const char *symbol, char *error, size_t errorsize );
extern int wine_dlclose( void *handle, char *error, size_t errorsize );
extern void wine_dll_set_callback( load_dll_callback_t load );
extern void *wine_dll_load( const char *filename, char *error, int errorsize, int *file_exists );
extern void *wine_dll_load_main_exe( const char *name, char *error, int errorsize,

View File

@ -121,13 +121,15 @@ void wine_dbg_add_option( const char *name, unsigned char set, unsigned char cle
{
struct dll *dll = first_dll;
struct debug_option *opt;
size_t len = strlen(name);
if (!(opt = malloc( sizeof(*opt) ))) return;
opt->next = NULL;
opt->set = set;
opt->clear = clear;
strncpy( opt->name, name, sizeof(opt->name) );
opt->name[sizeof(opt->name)-1] = 0;
if (len >= sizeof(opt->name)) len = sizeof(opt->name) - 1;
memcpy( opt->name, name, len );
opt->name[len] = 0;
if (last_option) last_option->next = opt;
else first_option = opt;
last_option = opt;

View File

@ -558,7 +558,7 @@ void wine_init( int argc, char *argv[], char *error, int error_size )
/***********************************************************************
* wine_dlopen
*/
void *wine_dlopen( const char *filename, int flag, char *error, int errorsize )
void *wine_dlopen( const char *filename, int flag, char *error, size_t errorsize )
{
#ifdef HAVE_DLOPEN
void *ret;
@ -566,18 +566,26 @@ void *wine_dlopen( const char *filename, int flag, char *error, int errorsize )
dlerror(); dlerror();
ret = dlopen( filename, flag );
s = dlerror();
if (error)
if (error && errorsize)
{
strncpy( error, s ? s : "", errorsize );
error[errorsize - 1] = '\0';
if (s)
{
size_t len = strlen(s);
if (len >= errorsize) len = errorsize - 1;
memcpy( error, s, len );
error[len] = 0;
}
else error[0] = 0;
}
dlerror();
return ret;
#else
if (error)
{
strncpy( error, "dlopen interface not detected by configure", errorsize );
error[errorsize - 1] = '\0';
static const char msg[] = "dlopen interface not detected by configure";
size_t len = min( errorsize, sizeof(msg) );
memcpy( error, msg, len );
error[len - 1] = 0;
}
return NULL;
#endif
@ -586,7 +594,7 @@ void *wine_dlopen( const char *filename, int flag, char *error, int errorsize )
/***********************************************************************
* wine_dlsym
*/
void *wine_dlsym( void *handle, const char *symbol, char *error, int errorsize )
void *wine_dlsym( void *handle, const char *symbol, char *error, size_t errorsize )
{
#ifdef HAVE_DLOPEN
void *ret;
@ -594,18 +602,26 @@ void *wine_dlsym( void *handle, const char *symbol, char *error, int errorsize )
dlerror(); dlerror();
ret = dlsym( handle, symbol );
s = dlerror();
if (error)
if (error && errorsize)
{
strncpy( error, s ? s : "", errorsize );
error[errorsize - 1] = '\0';
if (s)
{
size_t len = strlen(s);
if (len >= errorsize) len = errorsize - 1;
memcpy( error, s, len );
error[len] = 0;
}
else error[0] = 0;
}
dlerror();
return ret;
#else
if (error)
{
strncpy( error, "dlopen interface not detected by configure", errorsize );
error[errorsize - 1] = '\0';
static const char msg[] = "dlopen interface not detected by configure";
size_t len = min( errorsize, sizeof(msg) );
memcpy( error, msg, len );
error[len - 1] = 0;
}
return NULL;
#endif
@ -614,7 +630,7 @@ void *wine_dlsym( void *handle, const char *symbol, char *error, int errorsize )
/***********************************************************************
* wine_dlclose
*/
int wine_dlclose( void *handle, char *error, int errorsize )
int wine_dlclose( void *handle, char *error, size_t errorsize )
{
#ifdef HAVE_DLOPEN
int ret;
@ -622,18 +638,26 @@ int wine_dlclose( void *handle, char *error, int errorsize )
dlerror(); dlerror();
ret = dlclose( handle );
s = dlerror();
if (error)
if (error && errorsize)
{
strncpy( error, s ? s : "", errorsize );
error[errorsize - 1] = '\0';
if (s)
{
size_t len = strlen(s);
if (len >= errorsize) len = errorsize - 1;
memcpy( error, s, len );
error[len] = 0;
}
else error[0] = 0;
}
dlerror();
return ret;
#else
if (error)
{
strncpy( error, "dlopen interface not detected by configure", errorsize );
error[errorsize - 1] = '\0';
static const char msg[] = "dlopen interface not detected by configure";
size_t len = min( errorsize, sizeof(msg) );
memcpy( error, msg, len );
error[len - 1] = 0;
}
return 1;
#endif

View File

@ -163,7 +163,6 @@ static void fill_fontinfo(FT_Face face, int enc, FILE *fp, int dpi, unsigned cha
int num_names;
const union cptable *cptable;
FT_SfntName sfntname;
char namebuf[4096];
TT_OS2 *os2;
cptable = wine_cp_get_table(enc);
if(!cptable) {
@ -207,13 +206,12 @@ static void fill_fontinfo(FT_Face face, int enc, FILE *fp, int dpi, unsigned cha
num_names = FT_Get_Sfnt_Name_Count(face);
for(i = 0; i <num_names; i++) {
FT_Get_Sfnt_Name(face, i, &sfntname);
memcpy(namebuf, sfntname.string, sfntname.string_len);
namebuf[sfntname.string_len] = '\0';
if(sfntname.platform_id == 1 && sfntname.encoding_id == 0 &&
sfntname.language_id == 0 && sfntname.name_id == 0) {
strncpy(hdr.dfCopyright, namebuf, 60);
hdr.dfCopyright[59] = '\0';
}
size_t len = min( sfntname.string_len, sizeof(hdr.dfCopyright)-1 );
memcpy(hdr.dfCopyright, sfntname.string, len);
hdr.dfCopyright[len] = 0;
}
}
os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);

View File

@ -86,15 +86,16 @@ void dump_data( const unsigned char *ptr, unsigned int size, const char *prefix
const char* get_time_str(DWORD _t)
{
time_t t = (time_t)_t;
const char *str = ctime(&t);
size_t len = strlen(str);
static char buf[128];
/* FIXME: I don't get the same values from MS' pedump running under Wine...
* I wonder if Wine isn't broken wrt to GMT settings...
*/
strncpy(buf, ctime(&t), sizeof(buf));
buf[sizeof(buf) - 1] = '\0';
if (buf[strlen(buf)-1] == '\n')
buf[strlen(buf)-1] = '\0';
if (len && str[len-1] == '\n') len--;
if (len >= sizeof(buf)) len = sizeof(buf) - 1;
memcpy( buf, str, len );
buf[len] = 0;
return buf;
}