mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-31 12:54:13 +00:00
Remove a few more instances of strncpy.
This commit is contained in:
parent
172e731c0b
commit
240d4ee9e1
7 changed files with 88 additions and 49 deletions
|
@ -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* _mbsncpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
|
||||||
{
|
{
|
||||||
|
unsigned char* ret = dst;
|
||||||
if(!n)
|
if(!n)
|
||||||
return dst;
|
return dst;
|
||||||
if(MSVCRT___mb_cur_max > 1)
|
if(MSVCRT___mb_cur_max > 1)
|
||||||
{
|
{
|
||||||
unsigned char* ret = dst;
|
while (*src && n)
|
||||||
while (*src && n--)
|
|
||||||
{
|
{
|
||||||
|
n--;
|
||||||
*dst++ = *src;
|
*dst++ = *src;
|
||||||
if (MSVCRT_isleadbyte(*src++))
|
if (MSVCRT_isleadbyte(*src++))
|
||||||
*dst++ = *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* _mbsnbcpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
|
||||||
{
|
{
|
||||||
|
unsigned char* ret = dst;
|
||||||
if(!n)
|
if(!n)
|
||||||
return dst;
|
return dst;
|
||||||
if(MSVCRT___mb_cur_max > 1)
|
if(MSVCRT___mb_cur_max > 1)
|
||||||
{
|
{
|
||||||
unsigned char* ret = dst;
|
while (*src && (n > 1))
|
||||||
while (*src && (n-- > 1))
|
|
||||||
{
|
{
|
||||||
|
n--;
|
||||||
*dst++ = *src;
|
*dst++ = *src;
|
||||||
if (MSVCRT_isleadbyte(*src++))
|
if (MSVCRT_isleadbyte(*src++))
|
||||||
{
|
{
|
||||||
|
@ -268,11 +276,17 @@ unsigned char* _mbsnbcpy(unsigned char* dst, const unsigned char* src, MSVCRT_si
|
||||||
*dst++ = *src;
|
*dst++ = *src;
|
||||||
n--;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
|
|
|
@ -1515,9 +1515,9 @@ NTSTATUS WINAPI NtQueryVolumeInformationFile( HANDLE handle, PIO_STATUS_BLOCK io
|
||||||
mach_port_t masterPort;
|
mach_port_t masterPort;
|
||||||
|
|
||||||
char bsdName[6]; /* disk#\0 */
|
char bsdName[6]; /* disk#\0 */
|
||||||
|
const char *name = stfs.f_mntfromname + strlen(_PATH_DEV);
|
||||||
strncpy(bsdName, stfs.f_mntfromname+strlen(_PATH_DEV) , 5);
|
memcpy( bsdName, name, min(strlen(name)+1,sizeof(bsdName)) );
|
||||||
bsdName[5] = 0;
|
bsdName[sizeof(bsdName)-1] = 0;
|
||||||
|
|
||||||
kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);
|
kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);
|
||||||
|
|
||||||
|
|
|
@ -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 * );
|
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_dlopen( const char *filename, int flag, char *error, size_t errorsize );
|
||||||
extern void *wine_dlsym( void *handle, const char *symbol, char *error, int errorsize );
|
extern void *wine_dlsym( void *handle, const char *symbol, char *error, size_t errorsize );
|
||||||
extern int wine_dlclose( void *handle, char *error, int 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_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( const char *filename, char *error, int errorsize, int *file_exists );
|
||||||
extern void *wine_dll_load_main_exe( const char *name, char *error, int errorsize,
|
extern void *wine_dll_load_main_exe( const char *name, char *error, int errorsize,
|
||||||
|
|
|
@ -121,13 +121,15 @@ void wine_dbg_add_option( const char *name, unsigned char set, unsigned char cle
|
||||||
{
|
{
|
||||||
struct dll *dll = first_dll;
|
struct dll *dll = first_dll;
|
||||||
struct debug_option *opt;
|
struct debug_option *opt;
|
||||||
|
size_t len = strlen(name);
|
||||||
|
|
||||||
if (!(opt = malloc( sizeof(*opt) ))) return;
|
if (!(opt = malloc( sizeof(*opt) ))) return;
|
||||||
opt->next = NULL;
|
opt->next = NULL;
|
||||||
opt->set = set;
|
opt->set = set;
|
||||||
opt->clear = clear;
|
opt->clear = clear;
|
||||||
strncpy( opt->name, name, sizeof(opt->name) );
|
if (len >= sizeof(opt->name)) len = sizeof(opt->name) - 1;
|
||||||
opt->name[sizeof(opt->name)-1] = 0;
|
memcpy( opt->name, name, len );
|
||||||
|
opt->name[len] = 0;
|
||||||
if (last_option) last_option->next = opt;
|
if (last_option) last_option->next = opt;
|
||||||
else first_option = opt;
|
else first_option = opt;
|
||||||
last_option = opt;
|
last_option = opt;
|
||||||
|
|
|
@ -558,7 +558,7 @@ void wine_init( int argc, char *argv[], char *error, int error_size )
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* wine_dlopen
|
* 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
|
#ifdef HAVE_DLOPEN
|
||||||
void *ret;
|
void *ret;
|
||||||
|
@ -566,18 +566,26 @@ void *wine_dlopen( const char *filename, int flag, char *error, int errorsize )
|
||||||
dlerror(); dlerror();
|
dlerror(); dlerror();
|
||||||
ret = dlopen( filename, flag );
|
ret = dlopen( filename, flag );
|
||||||
s = dlerror();
|
s = dlerror();
|
||||||
if (error)
|
if (error && errorsize)
|
||||||
{
|
{
|
||||||
strncpy( error, s ? s : "", errorsize );
|
if (s)
|
||||||
error[errorsize - 1] = '\0';
|
{
|
||||||
|
size_t len = strlen(s);
|
||||||
|
if (len >= errorsize) len = errorsize - 1;
|
||||||
|
memcpy( error, s, len );
|
||||||
|
error[len] = 0;
|
||||||
|
}
|
||||||
|
else error[0] = 0;
|
||||||
}
|
}
|
||||||
dlerror();
|
dlerror();
|
||||||
return ret;
|
return ret;
|
||||||
#else
|
#else
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
strncpy( error, "dlopen interface not detected by configure", errorsize );
|
static const char msg[] = "dlopen interface not detected by configure";
|
||||||
error[errorsize - 1] = '\0';
|
size_t len = min( errorsize, sizeof(msg) );
|
||||||
|
memcpy( error, msg, len );
|
||||||
|
error[len - 1] = 0;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
|
@ -586,7 +594,7 @@ void *wine_dlopen( const char *filename, int flag, char *error, int errorsize )
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* wine_dlsym
|
* 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
|
#ifdef HAVE_DLOPEN
|
||||||
void *ret;
|
void *ret;
|
||||||
|
@ -594,18 +602,26 @@ void *wine_dlsym( void *handle, const char *symbol, char *error, int errorsize )
|
||||||
dlerror(); dlerror();
|
dlerror(); dlerror();
|
||||||
ret = dlsym( handle, symbol );
|
ret = dlsym( handle, symbol );
|
||||||
s = dlerror();
|
s = dlerror();
|
||||||
if (error)
|
if (error && errorsize)
|
||||||
{
|
{
|
||||||
strncpy( error, s ? s : "", errorsize );
|
if (s)
|
||||||
error[errorsize - 1] = '\0';
|
{
|
||||||
|
size_t len = strlen(s);
|
||||||
|
if (len >= errorsize) len = errorsize - 1;
|
||||||
|
memcpy( error, s, len );
|
||||||
|
error[len] = 0;
|
||||||
|
}
|
||||||
|
else error[0] = 0;
|
||||||
}
|
}
|
||||||
dlerror();
|
dlerror();
|
||||||
return ret;
|
return ret;
|
||||||
#else
|
#else
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
strncpy( error, "dlopen interface not detected by configure", errorsize );
|
static const char msg[] = "dlopen interface not detected by configure";
|
||||||
error[errorsize - 1] = '\0';
|
size_t len = min( errorsize, sizeof(msg) );
|
||||||
|
memcpy( error, msg, len );
|
||||||
|
error[len - 1] = 0;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
|
@ -614,7 +630,7 @@ void *wine_dlsym( void *handle, const char *symbol, char *error, int errorsize )
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* wine_dlclose
|
* wine_dlclose
|
||||||
*/
|
*/
|
||||||
int wine_dlclose( void *handle, char *error, int errorsize )
|
int wine_dlclose( void *handle, char *error, size_t errorsize )
|
||||||
{
|
{
|
||||||
#ifdef HAVE_DLOPEN
|
#ifdef HAVE_DLOPEN
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -622,18 +638,26 @@ int wine_dlclose( void *handle, char *error, int errorsize )
|
||||||
dlerror(); dlerror();
|
dlerror(); dlerror();
|
||||||
ret = dlclose( handle );
|
ret = dlclose( handle );
|
||||||
s = dlerror();
|
s = dlerror();
|
||||||
if (error)
|
if (error && errorsize)
|
||||||
{
|
{
|
||||||
strncpy( error, s ? s : "", errorsize );
|
if (s)
|
||||||
error[errorsize - 1] = '\0';
|
{
|
||||||
|
size_t len = strlen(s);
|
||||||
|
if (len >= errorsize) len = errorsize - 1;
|
||||||
|
memcpy( error, s, len );
|
||||||
|
error[len] = 0;
|
||||||
|
}
|
||||||
|
else error[0] = 0;
|
||||||
}
|
}
|
||||||
dlerror();
|
dlerror();
|
||||||
return ret;
|
return ret;
|
||||||
#else
|
#else
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
strncpy( error, "dlopen interface not detected by configure", errorsize );
|
static const char msg[] = "dlopen interface not detected by configure";
|
||||||
error[errorsize - 1] = '\0';
|
size_t len = min( errorsize, sizeof(msg) );
|
||||||
|
memcpy( error, msg, len );
|
||||||
|
error[len - 1] = 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -163,7 +163,6 @@ static void fill_fontinfo(FT_Face face, int enc, FILE *fp, int dpi, unsigned cha
|
||||||
int num_names;
|
int num_names;
|
||||||
const union cptable *cptable;
|
const union cptable *cptable;
|
||||||
FT_SfntName sfntname;
|
FT_SfntName sfntname;
|
||||||
char namebuf[4096];
|
|
||||||
TT_OS2 *os2;
|
TT_OS2 *os2;
|
||||||
cptable = wine_cp_get_table(enc);
|
cptable = wine_cp_get_table(enc);
|
||||||
if(!cptable) {
|
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);
|
num_names = FT_Get_Sfnt_Name_Count(face);
|
||||||
for(i = 0; i <num_names; i++) {
|
for(i = 0; i <num_names; i++) {
|
||||||
FT_Get_Sfnt_Name(face, i, &sfntname);
|
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 &&
|
if(sfntname.platform_id == 1 && sfntname.encoding_id == 0 &&
|
||||||
sfntname.language_id == 0 && sfntname.name_id == 0) {
|
sfntname.language_id == 0 && sfntname.name_id == 0) {
|
||||||
strncpy(hdr.dfCopyright, namebuf, 60);
|
size_t len = min( sfntname.string_len, sizeof(hdr.dfCopyright)-1 );
|
||||||
hdr.dfCopyright[59] = '\0';
|
memcpy(hdr.dfCopyright, sfntname.string, len);
|
||||||
}
|
hdr.dfCopyright[len] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
|
os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
|
||||||
|
|
|
@ -86,15 +86,16 @@ void dump_data( const unsigned char *ptr, unsigned int size, const char *prefix
|
||||||
const char* get_time_str(DWORD _t)
|
const char* get_time_str(DWORD _t)
|
||||||
{
|
{
|
||||||
time_t t = (time_t)_t;
|
time_t t = (time_t)_t;
|
||||||
|
const char *str = ctime(&t);
|
||||||
|
size_t len = strlen(str);
|
||||||
static char buf[128];
|
static char buf[128];
|
||||||
|
|
||||||
/* FIXME: I don't get the same values from MS' pedump running under Wine...
|
/* 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...
|
* I wonder if Wine isn't broken wrt to GMT settings...
|
||||||
*/
|
*/
|
||||||
strncpy(buf, ctime(&t), sizeof(buf));
|
if (len && str[len-1] == '\n') len--;
|
||||||
buf[sizeof(buf) - 1] = '\0';
|
if (len >= sizeof(buf)) len = sizeof(buf) - 1;
|
||||||
if (buf[strlen(buf)-1] == '\n')
|
memcpy( buf, str, len );
|
||||||
buf[strlen(buf)-1] = '\0';
|
buf[len] = 0;
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue