Fix issues detected by static analysis
This commit is contained in:
@@ -216,7 +216,8 @@ void GuiReadDotfile()
|
||||
|
||||
if(feof(dotfile)) break;
|
||||
if(*line == '#') continue;
|
||||
if(!sscanf(line, "%40[0-9a-zA-Z-]%n", symbol, &n)) continue;
|
||||
int result = sscanf(line, "%40[0-9a-zA-Z-]%n", symbol, &n);
|
||||
if(result == EOF || !result) continue;
|
||||
if(line[n] != ':') continue;
|
||||
|
||||
/* Separate line contents into symbol: value pair */
|
||||
|
||||
@@ -367,9 +367,9 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'o': if(!strcmp(optarg, "file"))
|
||||
case 'o': if(optarg && !strcmp(optarg, "file"))
|
||||
Closure->eccTarget = ECC_FILE;
|
||||
else if(!strcmp(optarg, "image"))
|
||||
else if(optarg && !strcmp(optarg, "image"))
|
||||
Closure->eccTarget = ECC_IMAGE;
|
||||
else Stop(_("-o/--ecc-target expects 'file' or 'image'"));
|
||||
break;
|
||||
|
||||
@@ -1189,7 +1189,7 @@ int GetLongestTranslation(char*, ...);
|
||||
void vLogWarning(char*, va_list);
|
||||
|
||||
void LogWarning(char*, ...) PRINTF_FORMAT(1);
|
||||
void Stop(char*, ...) PRINTF_FORMAT(1);
|
||||
void Stop(char*, ...) __attribute__((noreturn)) PRINTF_FORMAT(1);
|
||||
void RegisterCleanup(char*, void (*)(gpointer), gpointer);
|
||||
void UnregisterCleanup(void);
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ ReedSolomonTables *CreateReedSolomonTables(GaloisTables *gt,
|
||||
* respectively (ndata+sp) mod nroots = 0 after working in all ndata layers.
|
||||
*/
|
||||
|
||||
rt->shiftInit = rt->nroots - rt->ndata % rt->nroots;
|
||||
rt->shiftInit = (rt->nroots == 0 ? 0 : rt->nroots - rt->ndata % rt->nroots);
|
||||
if(rt->shiftInit == rt->nroots)
|
||||
rt->shiftInit = 0;
|
||||
|
||||
|
||||
@@ -689,6 +689,10 @@ void Stop(char *format, ...)
|
||||
{ FreeClosure();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* code below should never be reachable, exit to make static analysis happy,
|
||||
and make the ((noreturn)) attribute right in all cases */
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -86,7 +86,7 @@ static void open_defective_sector_file(RawBuffer *rb, char *path, LargeFile **fi
|
||||
#endif
|
||||
|
||||
dsh->nSectors = (length-sizeof(DefectiveSectorHeader))/dsh->sectorSize;
|
||||
if(dsh->nSectors*dsh->sectorSize+sizeof(DefectiveSectorHeader) != length)
|
||||
if((guint64)dsh->nSectors*dsh->sectorSize+sizeof(DefectiveSectorHeader) != length)
|
||||
Stop(_("Defective sector file is truncated"));
|
||||
|
||||
/* Expand the old non-C2 raw dumps to new size */
|
||||
@@ -99,7 +99,7 @@ static void open_defective_sector_file(RawBuffer *rb, char *path, LargeFile **fi
|
||||
PrintCLI(" * Expanding raw dump for sector %lld from 2352 to %d bytes *\n",
|
||||
(long long)dsh->lba, MAX_RAW_TRANSFER_SIZE);
|
||||
|
||||
buf = g_malloc(dsh->sectorSize*dsh->nSectors);
|
||||
buf = g_malloc((gsize)dsh->sectorSize*dsh->nSectors);
|
||||
for(i=0, ptr=buf; i<dsh->nSectors; i++, ptr+=2352)
|
||||
{ int n=LargeRead(*file, ptr, dsh->sectorSize);
|
||||
|
||||
@@ -210,7 +210,7 @@ int SaveDefectiveSector(RawBuffer *rb, int can_c2_scan)
|
||||
{ if(!LargeSeek(file, sizeof(DefectiveSectorHeader)))
|
||||
Stop(_("Failed seeking in defective sector file: %s"), strerror(errno));
|
||||
|
||||
cache_sectors = g_malloc(dsh->sectorSize*dsh->nSectors);
|
||||
cache_sectors = g_malloc((gsize)dsh->sectorSize*dsh->nSectors);
|
||||
for(i=0, idx=0; i<dsh->nSectors; i++, idx+=dsh->sectorSize)
|
||||
{ int n=LargeRead(file, cache_sectors+idx, dsh->sectorSize);
|
||||
|
||||
@@ -221,7 +221,7 @@ int SaveDefectiveSector(RawBuffer *rb, int can_c2_scan)
|
||||
|
||||
/* Store sectors which are not already cached */
|
||||
|
||||
offset = sizeof(DefectiveSectorHeader) + dsh->sectorSize*dsh->nSectors;
|
||||
offset = sizeof(DefectiveSectorHeader) + (guint64)dsh->sectorSize*dsh->nSectors;
|
||||
if(!LargeSeek(file, offset))
|
||||
Stop(_("Failed seeking in defective sector file: %s"), strerror(errno));
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ static void redraw_labels(cairo_t *cr, GtkWidget *widget, int erase_mask)
|
||||
while(*c && *c != ' ') /* find point to split text in middle */
|
||||
c++;
|
||||
|
||||
if(c) /* split text into two lines */
|
||||
if(*c) /* split text into two lines */
|
||||
{ *c = 0;
|
||||
h = draw_text(cr, Closure->readLinearCurve->layout,
|
||||
Closure->readAdaptiveSubtitle, x, y, Closure->foreground,
|
||||
|
||||
@@ -367,7 +367,7 @@ void RS01ScanImage(Method *method, Image* image, struct MD5Context *ecc_ctxt, in
|
||||
{ PrintProgress(msg,percent);
|
||||
|
||||
#ifdef WITH_GUI_YES
|
||||
if(Closure->guiMode && mode & CREATE_CRC)
|
||||
if(Closure->guiMode && mode & CREATE_CRC && wl)
|
||||
{ GuiSetProgress(wl->encPBar1, percent, 100);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,12 +88,13 @@ static gboolean spiral_idle_func(gpointer data)
|
||||
void RS01AddVerifyValues(Method *method, int percent,
|
||||
gint64 totalMissing, gint64 totalCrcErrors,
|
||||
gint64 newMissing, gint64 newCrcErrors)
|
||||
{ RS01Widgets *wl = (RS01Widgets*)method->widgetList;
|
||||
spiral_idle_info *sii = g_malloc(sizeof(spiral_idle_info));
|
||||
|
||||
{
|
||||
if(percent < 0 || percent > VERIFY_IMAGE_SEGMENTS)
|
||||
return;
|
||||
|
||||
RS01Widgets *wl = (RS01Widgets*)method->widgetList;
|
||||
spiral_idle_info *sii = g_malloc(sizeof(spiral_idle_info));
|
||||
|
||||
if(newMissing)
|
||||
{ GuiSetLabelText(wl->cmpMissingSectors, "<span %s>%" PRId64 "</span>",
|
||||
Closure->redMarkup, totalMissing);
|
||||
|
||||
@@ -678,10 +678,11 @@ RS02Layout *RS02LayoutFromImage(Image *image)
|
||||
if(expected_size == lay2->dataSectors+lay2->eccSectors)
|
||||
{ Verbose("--> confirmed layout variant 2\n");
|
||||
memcpy(lay, lay2, sizeof(RS02Layout));
|
||||
g_free(lay2);
|
||||
}
|
||||
else
|
||||
Verbose("--> FAIL: did not map to expected variants!\n");
|
||||
|
||||
g_free(lay2);
|
||||
}
|
||||
|
||||
goto finish;
|
||||
|
||||
@@ -90,12 +90,13 @@ static gboolean spiral_idle_func(gpointer data)
|
||||
|
||||
static void add_verify_values(Method *method, int percent,
|
||||
gint64 newMissing, gint64 newCrcErrors)
|
||||
{ RS02Widgets *wl = (RS02Widgets*)method->widgetList;
|
||||
spiral_idle_info *sii = g_malloc(sizeof(spiral_idle_info));
|
||||
|
||||
{
|
||||
if(percent < 0 || percent > VERIFY_IMAGE_SEGMENTS)
|
||||
return;
|
||||
|
||||
RS02Widgets *wl = (RS02Widgets*)method->widgetList;
|
||||
spiral_idle_info *sii = g_malloc(sizeof(spiral_idle_info));
|
||||
|
||||
sii->cmpSpiral = wl->cmpSpiral;
|
||||
|
||||
sii->segColor = Closure->greenSector;
|
||||
|
||||
@@ -409,6 +409,7 @@ RS03Layout *CalcRS03Layout(Image *image, int target)
|
||||
{ Verbose("CalcRS03Layout(): removed cached layout from RS03, wrong target\n");
|
||||
g_free(image->cachedLayout);
|
||||
}
|
||||
else
|
||||
{ Verbose("CalcRS03Layout(): returning cached layout (%s)\n",
|
||||
((RS03Layout*)image->cachedLayout)->target == ECC_FILE ? "file" : "augmented");
|
||||
memcpy(lay, image->cachedLayout, sizeof(RS03Layout));
|
||||
|
||||
@@ -100,12 +100,13 @@ static gboolean spiral_idle_func(gpointer data)
|
||||
|
||||
static void add_verify_values(Method *method, int percent,
|
||||
gint64 newMissing, gint64 newCrcErrors)
|
||||
{ RS03Widgets *wl = (RS03Widgets*)method->widgetList;
|
||||
spiral_idle_info *sii = g_malloc(sizeof(spiral_idle_info));
|
||||
|
||||
{
|
||||
if(percent < 0 || percent > VERIFY_IMAGE_SEGMENTS)
|
||||
return;
|
||||
|
||||
RS03Widgets *wl = (RS03Widgets*)method->widgetList;
|
||||
spiral_idle_info *sii = g_malloc(sizeof(spiral_idle_info));
|
||||
|
||||
sii->cmpSpiral = wl->cmpSpiral;
|
||||
|
||||
sii->segColor = Closure->greenSector;
|
||||
|
||||
@@ -1786,12 +1786,13 @@ static int query_copyright(DeviceHandle *dh)
|
||||
*/
|
||||
|
||||
static int check_sector(DeviceHandle *dh, GString *msg_out, guint64 sector, int n_sectors)
|
||||
{ AlignedBuffer *scratch = CreateAlignedBuffer(MAX_CLUSTER_SIZE);
|
||||
{
|
||||
int status,result;
|
||||
char *msg;
|
||||
|
||||
if(sector<2) return 4;
|
||||
|
||||
AlignedBuffer *scratch = CreateAlignedBuffer(MAX_CLUSTER_SIZE);
|
||||
status = read_dvd_sector(dh, scratch->buf, sector, n_sectors);
|
||||
FreeAlignedBuffer(scratch);
|
||||
|
||||
@@ -2161,10 +2162,10 @@ void SpinupDevice(DeviceHandle *dh)
|
||||
double elapsed;
|
||||
gulong ignore;
|
||||
|
||||
if(s>=dh->sectors) return;
|
||||
if(s>=dh->sectors) break;
|
||||
|
||||
status = ReadSectorsFast(dh, ab->buf, s, dh->clusterSize);
|
||||
if(status) return;
|
||||
if(status) break;
|
||||
|
||||
elapsed = g_timer_elapsed(timer, &ignore);
|
||||
if(elapsed > Closure->spinupDelay)
|
||||
|
||||
@@ -393,6 +393,7 @@ static IsoInfo* examine_iso(Image *image)
|
||||
{ case 0: Verbose(" -> boot record: *skipped*\n");
|
||||
break;
|
||||
case 1: Verbose(" -> primary volume descriptor:\n");
|
||||
if (ii) FreeIsoInfo(ii);
|
||||
ii = examine_primary_vd(buf);
|
||||
break;
|
||||
case 2: Verbose(" -> supplementary volume descriptor: *skipped*\n");
|
||||
|
||||
Reference in New Issue
Block a user