* Fix warn_unused_result compiler warnings with FORTIFY_SOURCE defined.

This commit is contained in:
Justin Maggard 2012-03-28 08:15:15 +00:00
parent 29738ed064
commit 40f3664390
8 changed files with 79 additions and 72 deletions

View File

@ -143,9 +143,13 @@ dlna_timestamp_is_present(const char * filename, int * raw_packet_size)
/* read file header */
fd = open(filename, O_RDONLY);
read(fd, buffer, MPEG_TS_PACKET_LENGTH_DLNA*3);
if( fd < 0 )
return 0;
i = read(fd, buffer, MPEG_TS_PACKET_LENGTH_DLNA*3);
close(fd);
for( i=0; i < MPEG_TS_PACKET_LENGTH_DLNA; i++ )
if( i < 0 )
return 0;
for( i = 0; i < MPEG_TS_PACKET_LENGTH_DLNA; i++ )
{
if( buffer[i] == MPEG_TS_SYNC_CODE )
{
@ -181,10 +185,13 @@ is_tivo_file(const char * path)
/* read file header */
fd = open(path, O_RDONLY);
read(fd, buf, 5);
if( !fd )
return 0;
if( read(fd, buf, 5) < 0 )
buf[0] = 'X';
close(fd);
return( !memcmp(buf, hdr, 5) );
return !memcmp(buf, hdr, 5);
}
#endif
@ -738,7 +745,6 @@ GetVideoMetadata(const char * path, char * name)
strip_ext(name);
//DEBUG DPRINTF(E_DEBUG, L_METADATA, " * size: %jd\n", file.st_size);
av_register_all();
#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(2<<8)+0)
if( avformat_open_input(&ctx, path, NULL, NULL) != 0 )
#else

View File

@ -350,7 +350,7 @@ init(int argc, char * * argv)
char * path;
char buf[PATH_MAX];
char ip_addr[INET_ADDRSTRLEN + 3] = {'\0'};
char log_str[72] = "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn";
char log_str[75] = "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn";
char *log_level = NULL;
/* first check if "-f" option is used */
@ -797,6 +797,8 @@ init(int argc, char * * argv)
if(debug_flag)
{
pid = getpid();
strcpy(log_str+65, "maxdebug");
log_level = log_str;
log_init(NULL, log_level);
}
else

View File

@ -33,6 +33,33 @@
#ifdef ENABLE_NLS
#include <libintl.h>
#endif
#if HAVE_FFMPEG_LIBAVUTIL_AVUTIL_H
#include <ffmpeg/libavutil/avutil.h>
#elif HAVE_LIBAV_LIBAVUTIL_AVUTIL_H
#include <libav/libavutil/avutil.h>
#elif HAVE_LIBAVUTIL_AVUTIL_H
#include <libavutil/avutil.h>
#elif HAVE_FFMPEG_AVUTIL_H
#include <ffmpeg/avutil.h>
#elif HAVE_LIBAV_AVUTIL_H
#include <libav/avutil.h>
#elif HAVE_AVUTIL_H
#include <avutil.h>
#endif
#if HAVE_FFMPEG_LIBAVFORMAT_AVFORMAT_H
#include <ffmpeg/libavformat/avformat.h>
#elif HAVE_LIBAV_LIBAVFORMAT_AVFORMAT_H
#include <libav/libavformat/avformat.h>
#elif HAVE_LIBAVFORMAT_AVFORMAT_H
#include <libavformat/avformat.h>
#elif HAVE_FFMPEG_AVFORMAT_H
#include <ffmpeg/avformat.h>
#elif HAVE_LIBAV_LIBAVFORMAT_H
#include <libav/avformat.h>
#elif HAVE_AVFORMAT_H
#include <avformat.h>
#endif
#include <sqlite3.h>
#include "upnpglobalvars.h"
@ -726,30 +753,28 @@ ScanDirectory(const char * dir, const char * parent, enum media_types dir_type)
enum file_types type;
setlocale(LC_COLLATE, "");
if( chdir(dir) != 0 )
return;
DPRINTF(parent?E_INFO:E_WARN, L_SCANNER, _("Scanning %s\n"), dir);
switch( dir_type )
{
case ALL_MEDIA:
n = scandir(".", &namelist, filter_media, alphasort);
n = scandir(dir, &namelist, filter_media, alphasort);
break;
case AUDIO_ONLY:
n = scandir(".", &namelist, filter_audio, alphasort);
n = scandir(dir, &namelist, filter_audio, alphasort);
break;
case VIDEO_ONLY:
n = scandir(".", &namelist, filter_video, alphasort);
n = scandir(dir, &namelist, filter_video, alphasort);
break;
case IMAGES_ONLY:
n = scandir(".", &namelist, filter_images, alphasort);
n = scandir(dir, &namelist, filter_images, alphasort);
break;
default:
n = -1;
break;
}
if (n < 0) {
fprintf(stderr, "Error scanning %s [scandir]\n", dir);
DPRINTF(E_WARN, L_SCANNER, "Error scanning %s\n", dir);
return;
}
@ -794,11 +819,7 @@ ScanDirectory(const char * dir, const char * parent, enum media_types dir_type)
free(namelist[i]);
}
free(namelist);
if( parent )
{
chdir(dirname((char*)dir));
}
else
if( !parent )
{
DPRINTF(E_WARN, L_SCANNER, _("Scanning %s finished (%llu files)!\n"), dir, fileno);
}
@ -818,7 +839,8 @@ start_scanner()
if( flag )
fclose(flag);
#endif
freopen("/dev/null", "a", stderr);
av_register_all();
av_log_set_level(AV_LOG_PANIC);
while( media_path )
{
strncpy(name, media_path->path, sizeof(name));
@ -826,7 +848,6 @@ start_scanner()
ScanDirectory(media_path->path, NULL, media_path->type);
media_path = media_path->next;
}
freopen("/proc/self/fd/2", "a", stderr);
#ifdef READYNAS
if( access("/ramfs/.rescan_done", F_OK) == 0 )
system("/bin/sh /ramfs/.rescan_done");

View File

@ -82,7 +82,8 @@ fget_byte(FILE *fp)
{
__u8 d;
(void)fread(&d, sizeof(d), 1, fp);
if (!fread(&d, sizeof(d), 1, fp))
return 0;
return d;
}
@ -91,7 +92,8 @@ fget_le16(FILE *fp)
{
__u16 d;
(void)fread(&d, sizeof(d), 1, fp);
if (!fread(&d, sizeof(d), 1, fp))
return 0;
d = le16_to_cpu(d);
return d;
}
@ -101,7 +103,8 @@ fget_le32(FILE *fp)
{
__u32 d;
(void)fread(&d, sizeof(d), 1, fp);
if (!fread(&d, sizeof(d), 1, fp))
return 0;
d = le32_to_cpu(d);
return d;
}

View File

@ -24,20 +24,6 @@
* This file is derived from mt-daap project.
*/
// _mac_to_unix_time
static time_t
_mac_to_unix_time(int t)
{
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
return (t - (365L * 66L * 24L * 60L * 60L + 17L * 60L * 60L * 24L) +
(tz.tz_minuteswest * 60));
}
// _aac_findatom:
static long
@ -278,7 +264,6 @@ _get_aacfileinfo(char *file, struct song_metadata *psong)
off_t file_size;
int ms;
unsigned char buffer[2];
int time = 0;
aac_object_type_t profile_id = 0;
psong->vbr_scale = -1;
@ -298,13 +283,10 @@ _get_aacfileinfo(char *file, struct song_metadata *psong)
atom_offset = _aac_lookforatom(infile, "moov:mvhd", (unsigned int*)&atom_length);
if(atom_offset != -1)
{
fseek(infile, 8, SEEK_CUR);
fread((void *)&time, sizeof(int), 1, infile);
time = ntohl(time);
// slimserver prefer to use filesystem time
//psong->time_modified = _mac_to_unix_time(time);
fread((void*)&sample_size, 1, sizeof(int), infile);
fread((void*)&samples, 1, sizeof(int), infile);
fseek(infile, 12, SEEK_CUR);
if(!fread((void*)&sample_size, 1, sizeof(int), infile) ||
!fread((void*)&samples, 1, sizeof(int), infile))
return -1;
sample_size = ntohl(sample_size);
samples = ntohl(samples);
@ -327,9 +309,8 @@ _get_aacfileinfo(char *file, struct song_metadata *psong)
atom_offset = _aac_lookforatom(infile, "moov:trak:mdia:minf:stbl:stsd:alac", (unsigned int*)&atom_length);
if(atom_offset != -1) {
fseek(infile, atom_offset + 32, SEEK_SET);
fread(buffer, sizeof(unsigned char), 2, infile);
psong->samplerate = (buffer[0] << 8) | (buffer[1]);
if (fread(buffer, sizeof(unsigned char), 2, infile) == 2)
psong->samplerate = (buffer[0] << 8) | (buffer[1]);
goto bad_esds;
}
@ -338,9 +319,8 @@ _get_aacfileinfo(char *file, struct song_metadata *psong)
if(atom_offset != -1)
{
fseek(infile, atom_offset + 32, SEEK_SET);
fread(buffer, sizeof(unsigned char), 2, infile);
psong->samplerate = (buffer[0] << 8) | (buffer[1]);
if(fread(buffer, sizeof(unsigned char), 2, infile) == 2)
psong->samplerate = (buffer[0] << 8) | (buffer[1]);
fseek(infile, 2, SEEK_CUR);
@ -352,25 +332,24 @@ _get_aacfileinfo(char *file, struct song_metadata *psong)
// skip the version number
fseek(infile, atom_offset + 4, SEEK_CUR);
// should be 0x03, to signify the descriptor type (section)
fread((void *)&buffer, 1, 1, infile);
if( (buffer[0] != 0x03) || (_aac_check_extended_descriptor(infile) != 0) )
if( !fread((void *)&buffer, 1, 1, infile) || (buffer[0] != 0x03) || (_aac_check_extended_descriptor(infile) != 0) )
goto bad_esds;
fseek(infile, 4, SEEK_CUR);
fread((void *)&buffer, 1, 1, infile);
if( (buffer[0] != 0x04) || (_aac_check_extended_descriptor(infile) != 0) )
if( !fread((void *)&buffer, 1, 1, infile) || (buffer[0] != 0x04) || (_aac_check_extended_descriptor(infile) != 0) )
goto bad_esds;
fseek(infile, 10, SEEK_CUR); // 10 bytes into section 4 should be average bitrate. max bitrate is 6 bytes in.
fread((void *)&bitrate, sizeof(unsigned int), 1, infile);
psong->bitrate = ntohl(bitrate);
fread((void *)&buffer, 1, 1, infile);
if( (buffer[0] != 0x05) || (_aac_check_extended_descriptor(infile) != 0) )
if(fread((void *)&bitrate, sizeof(unsigned int), 1, infile))
psong->bitrate = ntohl(bitrate);
if( !fread((void *)&buffer, 1, 1, infile) || (buffer[0] != 0x05) || (_aac_check_extended_descriptor(infile) != 0) )
goto bad_esds;
fseek(infile, 1, SEEK_CUR); // 1 bytes into section 5 should be the setup data
fread((void *)&buffer, 2, 1, infile);
profile_id = (buffer[0] >> 3); // first 5 bits of setup data is the Audo Profile ID
/* Frequency index: (((buffer[0] & 0x7) << 1) | (buffer[1] >> 7))) */
samples = ((buffer[1] >> 3) & 0xF);
psong->channels = (samples == 7 ? 8 : samples);
if(fread((void *)&buffer, 2, 1, infile))
{
profile_id = (buffer[0] >> 3); // first 5 bits of setup data is the Audo Profile ID
/* Frequency index: (((buffer[0] & 0x7) << 1) | (buffer[1] >> 7))) */
samples = ((buffer[1] >> 3) & 0xF);
psong->channels = (samples == 7 ? 8 : samples);
}
}
}
bad_esds:

View File

@ -23,4 +23,3 @@
static int _get_aactags(char *file, struct song_metadata *psong);
static int _get_aacfileinfo(char *file, struct song_metadata *psong);
static off_t _aac_lookforatom(FILE *aac_fp, char *atom_path, unsigned int *atom_length);
static time_t _mac_to_unix_time(int t) __attribute__((unused));

View File

@ -208,7 +208,8 @@ _asf_read_header_extension(FILE *fp, struct song_metadata *psong, __u32 size)
if(size < sizeof(asf_header_extension_t))
return -1;
fread(&ext.Reserved1, 1, sizeof(ext.Reserved1), fp);
if(sizeof(ext.Reserved1) != fread(&ext.Reserved1, 1, sizeof(ext.Reserved1), fp))
return -1;
ext.Reserved2 = fget_le16(fp);
ext.DataSize = fget_le32(fp);
@ -351,11 +352,7 @@ _asf_load_picture(FILE *fp, int size, void *bm, int *bm_size)
else
{
*bm_size = size;
if(size <= *bm_size)
{
fread(bm, 1, size, fp);
}
else
if(size > *bm_size || fread(bm, 1, size, fp) != size)
{
DPRINTF(E_ERROR, L_SCANNER, "Overrun %d bytes required\n", size);
free(bm);

2
uuid.c
View File

@ -98,7 +98,7 @@ read_random_bytes(unsigned char *buf, size_t size)
i = open("/dev/urandom", O_RDONLY);
if(i >= 0)
{
read(i, buf, size);
if(read(i, buf, size));
close(i);
}
/* Paranoia. /dev/urandom may be missing.