Fixes in asprintf usage.

This commit is contained in:
Fotis Panagiotopoulos 2023-04-12 18:42:28 +03:00 committed by Xiang Xiao
parent cf54069487
commit c50ff7ff61
7 changed files with 42 additions and 39 deletions

View File

@ -413,6 +413,8 @@ bool CResize::setWindowSize(FAR struct nxgl_size_s *size)
void CResize::updateSizeLabel(FAR struct nxgl_size_s &windowSize)
{
int ret;
// Do nothing if the size has not changed
struct nxgl_size_s labelSize;
@ -424,8 +426,8 @@ void CResize::updateSizeLabel(FAR struct nxgl_size_s &windowSize)
}
FAR char *str;
asprintf(&str, " %4d x %-4d ", windowSize.w, windowSize.h);
if (str == (FAR char *)0)
ret = asprintf(&str, " %4d x %-4d ", windowSize.w, windowSize.h);
if (ret < 0)
{
twmerr("ERROR: Failed to get size string\n");
return;

View File

@ -382,7 +382,10 @@ void CTwm4Nx::genMqName(void)
unsigned long randvalue =
(unsigned long)std::random() & 0x00fffffful;
std::asprintf(&m_queueName, "Twm4Nx%06lu", randvalue);
if (std::asprintf(&m_queueName, "Twm4Nx%06lu", randvalue) < 0)
{
m_queueName = NULL;
}
}
/**

View File

@ -247,7 +247,10 @@ static FAR char *ftpc_abspath(FAR struct ftpc_session_s *session,
else if (relpath[1] == '/')
{
asprintf(&ptr, "%s%s", homedir, &relpath[1]);
if (asprintf(&ptr, "%s%s", homedir, &relpath[1]) < 0)
{
ptr = NULL;
}
}
/* Hmmm... this pretty much guaranteed to fail */
@ -264,7 +267,10 @@ static FAR char *ftpc_abspath(FAR struct ftpc_session_s *session,
else if (strncmp(relpath, "./", 2) == 0)
{
asprintf(&ptr, "%s%s", curdir, relpath + 1);
if (asprintf(&ptr, "%s%s", curdir, relpath + 1) < 0)
{
ptr = NULL;
}
}
/* Check for an absolute path */
@ -278,7 +284,10 @@ static FAR char *ftpc_abspath(FAR struct ftpc_session_s *session,
else
{
asprintf(&ptr, "%s/%s", curdir, relpath);
if (asprintf(&ptr, "%s/%s", curdir, relpath) < 0)
{
ptr = NULL;
}
}
return ptr;

View File

@ -1007,12 +1007,13 @@ static ssize_t ftpd_response(int sd, int timeout, FAR const char *fmt, ...)
FAR char *buffer;
ssize_t bytessent;
va_list ap;
int ret;
va_start(ap, fmt);
vasprintf(&buffer, fmt, ap);
ret = vasprintf(&buffer, fmt, ap);
va_end(ap);
if (buffer == NULL)
if (ret < 0)
{
return -ENOMEM;
}
@ -2417,8 +2418,8 @@ static int fptd_listscan(FAR struct ftpd_session_s *session, FAR char *path,
}
}
asprintf(&temp, "%s/%s", path, entry->d_name);
if (temp == NULL)
ret = asprintf(&temp, "%s/%s", path, entry->d_name);
if (ret < 0)
{
continue;
}

View File

@ -121,7 +121,6 @@ static int critmon_process_directory(FAR struct dirent *entryp)
FAR char *maxrun;
FAR char *endptr;
FILE *stream;
int errcode;
int len;
int ret;
@ -134,13 +133,11 @@ static int critmon_process_directory(FAR struct dirent *entryp)
ret = asprintf(&filepath,
CONFIG_SYSTEM_CRITMONITOR_MOUNTPOINT "/%s/status",
entryp->d_name);
if (ret < 0 || filepath == NULL)
if (ret < 0)
{
errcode = errno;
fprintf(stderr,
"Csection Monitor: Failed to create path to status file: %d\n",
errcode);
return -errcode;
"Csection Monitor: Failed to create path to status file\n");
return -ENOMEM;
}
/* Open the status file */
@ -187,12 +184,10 @@ static int critmon_process_directory(FAR struct dirent *entryp)
ret = asprintf(&filepath,
CONFIG_SYSTEM_CRITMONITOR_MOUNTPOINT "/%s/critmon",
entryp->d_name);
if (ret < 0 || filepath == NULL)
if (ret < 0)
{
errcode = errno;
fprintf(stderr, "Csection Monitor: "
"Failed to create path to Csection file: %d\n",
errcode);
"Failed to create path to Csection file\n");
ret = -EINVAL;
goto errout_with_name;
}
@ -324,12 +319,10 @@ static void critmon_global_crit(void)
ret = asprintf(&filepath,
CONFIG_SYSTEM_CRITMONITOR_MOUNTPOINT "/critmon");
if (ret < 0 || filepath == NULL)
if (ret < 0)
{
errcode = errno;
fprintf(stderr, "Csection Monitor: "
"Failed to create path to Csection file: %d\n",
errcode);
"Failed to create path to Csection file\n");
return;
}

View File

@ -121,7 +121,6 @@ static int stkmon_process_directory(FAR struct dirent *entryp)
FILE *stream;
unsigned long stack_size;
unsigned long stack_used;
int errcode;
int len;
int ret;
@ -134,13 +133,11 @@ static int stkmon_process_directory(FAR struct dirent *entryp)
ret = asprintf(&filepath,
CONFIG_SYSTEM_STACKMONITOR_MOUNTPOINT "/%s/status",
entryp->d_name);
if (ret < 0 || filepath == NULL)
if (ret < 0)
{
errcode = errno;
fprintf(stderr,
"Stack Monitor: Failed to create path to status file: %d\n",
errcode);
return -errcode;
"Stack Monitor: Failed to create path to status file\n");
return -ENOMEM;
}
/* Open the status file */
@ -189,12 +186,10 @@ static int stkmon_process_directory(FAR struct dirent *entryp)
ret = asprintf(&filepath,
CONFIG_SYSTEM_STACKMONITOR_MOUNTPOINT "/%s/stack",
entryp->d_name);
if (ret < 0 || filepath == NULL)
if (ret < 0)
{
errcode = errno;
fprintf(stderr,
"Stack Monitor: Failed to create path to stack file: %d\n",
errcode);
"Stack Monitor: Failed to create path to stack file\n");
ret = -EINVAL;
goto errout_with_name;
}

View File

@ -1143,8 +1143,8 @@ static int zmr_parsefilename(FAR struct zmr_state_s *pzmr,
/* Extend the relative path to the file storage directory */
asprintf(&pzmr->filename, "%s/%s", pzmr->pathname, namptr);
if (!pzmr->filename)
ret = asprintf(&pzmr->filename, "%s/%s", pzmr->pathname, namptr);
if (ret < 0)
{
zmdbg("ERROR: Failed to allocate full path %s/%s\n",
CONFIG_SYSTEM_ZMODEM_MOUNTPOINT, namptr);
@ -1331,9 +1331,9 @@ static int zmr_parsefilename(FAR struct zmr_state_s *pzmr,
{
/* Create a candidate file name */
asprintf(&candidate, "%s_%" PRId32, pzmr->filename,
++uniqno);
if (!candidate)
ret = asprintf(&candidate, "%s_%" PRId32, pzmr->filename,
++uniqno);
if (ret < 0)
{
zmdbg("ERROR: Failed to allocate candidate %s_%d\n",
pzmr->filename, uniqno);