mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Fixed crash when using rs_sprintf/bd_sprintf or rs_sprintf_append/bd_sprintf_append with empty result (maybe only on Windows).
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5349 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
6a24bdc62c
commit
2367653146
@ -41,7 +41,7 @@ static int vasprintf(char **sptr, const char *fmt, va_list argv)
|
||||
return wanted;
|
||||
}
|
||||
|
||||
//int asprintf(char **sptr, const char *fmt, ...)
|
||||
//static int asprintf(char **sptr, const char *fmt, ...)
|
||||
//{
|
||||
// int retval;
|
||||
// va_list argv;
|
||||
@ -54,15 +54,23 @@ static int vasprintf(char **sptr, const char *fmt, va_list argv)
|
||||
|
||||
int bd_sprintf(std::string &str, const char *fmt, ...)
|
||||
{
|
||||
char *buffer;
|
||||
char *buffer = NULL;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
int retval = vasprintf(&buffer, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
str = buffer;
|
||||
free(buffer);
|
||||
if (retval >= 0) {
|
||||
if (buffer) {
|
||||
str = buffer;
|
||||
free(buffer);
|
||||
} else {
|
||||
str.clear();
|
||||
}
|
||||
} else {
|
||||
str.clear();
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
@ -70,14 +78,18 @@ int bd_sprintf(std::string &str, const char *fmt, ...)
|
||||
int bd_sprintf_append(std::string &str, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *ret;
|
||||
char *buffer = NULL;
|
||||
|
||||
va_start(ap, fmt);
|
||||
int retval = vasprintf(&ret, fmt, ap);
|
||||
int retval = vasprintf(&buffer, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
str.append(ret);
|
||||
free(ret);
|
||||
if (retval >= 0) {
|
||||
if (buffer) {
|
||||
str.append(buffer);
|
||||
free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
@ -230,15 +230,23 @@ static int vasprintf(char **sptr, const char *fmt, va_list argv)
|
||||
|
||||
int rs_sprintf(std::string &str, const char *fmt, ...)
|
||||
{
|
||||
char *buffer;
|
||||
char *buffer = NULL;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
int retval = vasprintf(&buffer, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
str = buffer;
|
||||
free(buffer);
|
||||
if (retval >= 0) {
|
||||
if (buffer) {
|
||||
str = buffer;
|
||||
free(buffer);
|
||||
} else {
|
||||
str.clear();
|
||||
}
|
||||
} else {
|
||||
str.clear();
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
@ -246,14 +254,18 @@ int rs_sprintf(std::string &str, const char *fmt, ...)
|
||||
int rs_sprintf_append(std::string &str, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *ret;
|
||||
char *buffer = NULL;
|
||||
|
||||
va_start(ap, fmt);
|
||||
int retval = vasprintf(&ret, fmt, ap);
|
||||
int retval = vasprintf(&buffer, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
str.append(ret);
|
||||
free(ret);
|
||||
if (retval >= 0) {
|
||||
if (buffer) {
|
||||
str.append(buffer);
|
||||
free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user