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

View File

@ -350,7 +350,7 @@ init(int argc, char * * argv)
char * path; char * path;
char buf[PATH_MAX]; char buf[PATH_MAX];
char ip_addr[INET_ADDRSTRLEN + 3] = {'\0'}; 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; char *log_level = NULL;
/* first check if "-f" option is used */ /* first check if "-f" option is used */
@ -797,6 +797,8 @@ init(int argc, char * * argv)
if(debug_flag) if(debug_flag)
{ {
pid = getpid(); pid = getpid();
strcpy(log_str+65, "maxdebug");
log_level = log_str;
log_init(NULL, log_level); log_init(NULL, log_level);
} }
else else

View File

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

View File

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

View File

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

View File

@ -23,4 +23,3 @@
static int _get_aactags(char *file, struct song_metadata *psong); static int _get_aactags(char *file, struct song_metadata *psong);
static int _get_aacfileinfo(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 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)) if(size < sizeof(asf_header_extension_t))
return -1; 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.Reserved2 = fget_le16(fp);
ext.DataSize = fget_le32(fp); ext.DataSize = fget_le32(fp);
@ -351,11 +352,7 @@ _asf_load_picture(FILE *fp, int size, void *bm, int *bm_size)
else else
{ {
*bm_size = size; *bm_size = size;
if(size <= *bm_size) if(size > *bm_size || fread(bm, 1, size, fp) != size)
{
fread(bm, 1, size, fp);
}
else
{ {
DPRINTF(E_ERROR, L_SCANNER, "Overrun %d bytes required\n", size); DPRINTF(E_ERROR, L_SCANNER, "Overrun %d bytes required\n", size);
free(bm); 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); i = open("/dev/urandom", O_RDONLY);
if(i >= 0) if(i >= 0)
{ {
read(i, buf, size); if(read(i, buf, size));
close(i); close(i);
} }
/* Paranoia. /dev/urandom may be missing. /* Paranoia. /dev/urandom may be missing.