1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

libtt: Resolve coverity warnings

This commit is contained in:
Peter Howkins 2018-04-11 19:31:03 +01:00
parent db88cb0d13
commit 30ad8e35e5
11 changed files with 50 additions and 38 deletions

View file

@ -231,10 +231,12 @@ static int original_umask = 0; /* for restoring */
static char *
copystring(const char *src)
{
int len = strlen (src);
int len;
char *cp;
if (!src) return NULL;
len = strlen (src);
cp = malloc (len + 1);
if (cp)
strcpy (cp, src);
@ -1256,6 +1258,7 @@ do_add(char *inputfilename, int lineno, int argc, char *argv[])
prefix (inputfilename, lineno);
fprintf (stderr,
"protodata_hex contains odd number of or non-hex characters\n");
free(protodata);
return (1);
}
}
@ -1290,6 +1293,7 @@ do_add(char *inputfilename, int lineno, int argc, char *argv[])
fprintf (stderr,
"authdata_hex contains odd number of or non-hex characters\n");
free (protodata);
free (authdata);
return (1);
}
}

View file

@ -239,6 +239,7 @@ _tt_get_record(int prefix_len, const char *prefix, const char *db_name, char *re
isfd = stat(dblong,&statbuf);
if (-1==isfd) {
_tt_syslog(errstr, LOG_ERR, "%s: %m", dblong);
free(db);
free(dblong);
return 0;
}
@ -300,6 +301,7 @@ _tt_write_record(int prefix_len, const char *prefix, const char *db_name,
isfd = stat(dblong,&statbuf);
if (-1==isfd) {
_tt_syslog(errstr, LOG_ERR, "%s: %m", dblong);
free(db);
free(dblong);
return 0;
}

View file

@ -248,6 +248,7 @@ realtrees( _Tt_string_list_ptr paths, bool_t follow_symlinks )
strncat( resolved_path_buf,
base, MAXPATHLEN - len );
}
free(dir);
}
} else {
resolved_path = _tt_get_realpath( (char *)path,

View file

@ -427,8 +427,7 @@ _ttds_file_server(const char *filename, const char **hostname)
_Tt_string partition;
_Tt_string network_path;
*hostname = "";
if (filename==0 || hostname==0) {
if (filename == NULL || hostname == NULL) {
return TT_ERR_POINTER;
}
filename_s = filename;

View file

@ -2476,7 +2476,7 @@ _tt_message_context_bval(Tt_message m, const char *slotname,
}
*len = value.len();
*val = (unsigned char *)_tt_strdup( value, *len );
if (val == 0) {
if (*val == NULL) {
return TT_ERR_NOMEM;
}
return TT_OK;

View file

@ -291,6 +291,8 @@ write_auth_file(char *filename)
else
(void) unlink(tmpnam);
free(tmpnam);
return TT_OK;
}
Tt_status _Tt_auth::
@ -306,7 +308,10 @@ retrieve_auth_cookie()
return TT_AUTHFILE_ENTRY_MISSING;
buff = (char*) malloc(entry->auth_data_length + 1);
if (NULL == buff) return TT_ERR_NOMEM;
if (NULL == buff) {
_tt_FreeAuthFileEntry(entry);
return TT_ERR_NOMEM;
}
strncpy(buff, entry->auth_data, entry->auth_data_length);
buff[entry->auth_data_length] = '\0';

View file

@ -159,7 +159,7 @@ _unlink_datfile(isfname)
{
char namebuf[MAXPATHLEN];
(void) strcpy(namebuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
_makedat_isfname(namebuf);
(void)unlink(namebuf);
@ -172,7 +172,7 @@ _unlink_indfile(isfname)
{
char namebuf[MAXPATHLEN];
(void) strcpy(namebuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
_makeind_isfname(namebuf);
(void)unlink(namebuf);
@ -185,7 +185,7 @@ _unlink_varfile(isfname)
{
char namebuf[MAXPATHLEN];
(void) strcpy(namebuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
_makevar_isfname(namebuf);
(void)unlink(namebuf);

View file

@ -197,8 +197,11 @@ _isfcb_open(isfname, errcode)
* Open the UNIX file for .rec file.
*/
if ((dat_fd = _open_datfile (isfname, &rdonly)) == -1 || errno == EMFILE) {
_amseterrcode(errcode, errno);
return (NULL);
_amseterrcode(errcode, errno);
if(dat_fd != -1) {
close(dat_fd);
}
return (NULL);
}
/*
@ -640,7 +643,7 @@ _create_datfile(isfname)
int fd;
char namebuf[MAXPATHLEN];
(void) strcpy(namebuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
_makedat_isfname(namebuf);
fd = open (namebuf, O_CREAT | O_EXCL | O_RDWR, 0666);
@ -663,7 +666,7 @@ _create_indfile(isfname)
int fd;
char namebuf[MAXPATHLEN];
(void) strcpy(namebuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
_makeind_isfname(namebuf);
fd = open (namebuf, O_CREAT | O_EXCL | O_RDWR, 0666);
@ -686,7 +689,7 @@ _create_varfile(isfname)
int fd;
char namebuf[MAXPATHLEN];
(void) strcpy(namebuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
_makevar_isfname(namebuf);
fd = open (namebuf, O_CREAT | O_EXCL | O_RDWR, 0666);
@ -709,7 +712,7 @@ _remove_datfile(isfname)
{
char namebuf[MAXPATHLEN];
(void) strcpy(namebuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
_makedat_isfname(namebuf);
(void) unlink(namebuf);
@ -727,7 +730,7 @@ _remove_indfile(isfname)
{
char namebuf[MAXPATHLEN];
(void) strcpy(namebuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
_makeind_isfname(namebuf);
(void) unlink(namebuf);
@ -745,7 +748,7 @@ _remove_varfile(isfname)
{
char namebuf[MAXPATHLEN];
(void) strcpy(namebuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
_makevar_isfname(namebuf);
(void) unlink(namebuf);
@ -766,7 +769,7 @@ _open_datfile(isfname, rdonly)
char namebuf[MAXPATHLEN];
int ret;
(void) strcpy(namebuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
_makedat_isfname(namebuf);
if ((ret = open (namebuf, O_RDWR)) != -1) {
@ -797,7 +800,7 @@ _open_indfile(isfname, rdonly)
int fd;
char namebuf[MAXPATHLEN];
(void) strcpy(namebuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
_makeind_isfname(namebuf);
fd = open (namebuf, (rdonly==TRUE)?O_RDONLY:O_RDWR);
@ -821,7 +824,7 @@ _open_varfile(isfname, rdonly)
int fd;
char namebuf[MAXPATHLEN];
(void) strcpy(namebuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
_makevar_isfname(namebuf);
fd = open (namebuf, (rdonly==TRUE)?O_RDONLY:O_RDWR);
@ -867,7 +870,7 @@ _open2_indfile(fcb)
if (fcb->indfd != -1)
return (ISOK);
(void) strcpy(namebuf, fcb->isfname);
snprintf(namebuf, sizeof(namebuf), "%s", fcb->isfname);
_makeind_isfname(namebuf);
(void)fstat(fcb->datfd, &buf);

View file

@ -42,8 +42,7 @@ isgarbage(char * isfname)
struct stat statbuf;
int count = 0,i;
(void)strcpy(isfname2, isfname);
(void)strcat(isfname2, "~");
snprintf(isfname2, sizeof(isfname2), "%s~", isfname);
if ((isfd = isopen(isfname, ISEXCLLOCK + ISINPUT)) == ISERROR) {
goto ERROR;

View file

@ -130,7 +130,7 @@ isrename(oldname, newname)
* still thinks that the file exists for a few seconds.
*/
(void)strcpy(datfname, oldname);
snprintf(datfname, sizeof(datfname), "%s", oldname);
_makedat_isfname(datfname);
(void)unlink(datfname);
@ -218,16 +218,16 @@ _rename_datfile(isfname, newname)
char namebuf[MAXPATHLEN];
char newbuf[MAXPATHLEN];
(void) strcpy(namebuf, isfname);
(void) strcpy(newbuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
snprintf(newbuf, sizeof(newbuf), "%s", isfname);
/*
* Replace the last element of the old path with newname.
*/
_removelast(newbuf);
if (strcmp(newbuf, "/") != 0)
(void) strcat(newbuf, "/");
(void)strcat(newbuf, newname);
snprintf(newbuf, sizeof(newbuf), "%s/", newbuf);
snprintf(newbuf, sizeof(newbuf), "%s%s", newbuf, newname);
_makedat_isfname(namebuf);
_makedat_isfname(newbuf);
@ -243,16 +243,16 @@ _rename_indfile(isfname, newname)
char namebuf[MAXPATHLEN];
char newbuf[MAXPATHLEN];
(void) strcpy(namebuf, isfname);
(void) strcpy(newbuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
snprintf(newbuf, sizeof(newbuf), "%s", isfname);
/*
* Replace the last element of the old path with newname.
*/
_removelast(newbuf);
if (strcmp(newbuf, "/") != 0)
(void) strcat(newbuf, "/");
(void)strcat(newbuf, newname);
snprintf(newbuf, sizeof(newbuf), "%s/", newbuf);
snprintf(newbuf, sizeof(newbuf), "%s%s", newbuf, newname);
_makeind_isfname(namebuf);
_makeind_isfname(newbuf);
@ -268,16 +268,16 @@ _rename_varfile(isfname, newname)
char namebuf[MAXPATHLEN];
char newbuf[MAXPATHLEN];
(void) strcpy(namebuf, isfname);
(void) strcpy(newbuf, isfname);
snprintf(namebuf, sizeof(namebuf), "%s", isfname);
snprintf(newbuf, sizeof(newbuf), "%s", isfname);
/*
* Replace the last element of the old path with newname.
*/
_removelast(newbuf);
if (strcmp(newbuf, "/") != 0)
(void) strcat(newbuf, "/");
(void)strcat(newbuf, newname);
snprintf(newbuf, sizeof(newbuf), "%s/", newbuf);
snprintf(newbuf, sizeof(newbuf), "%s%s", newbuf, newname);
_makevar_isfname(namebuf);
_makevar_isfname(newbuf);

View file

@ -591,8 +591,7 @@ _amstart(isfhandle, record, reclen, readmode,
_amseterrcode(errcode, ISOK);
/* Clean-up work. */
if (newcrp != NULL)
free(newcrp);
free(newcrp);
_isdisk_commit(); /* This will only check
* that we unfixed all fixed