diff --git a/src/closure.c b/src/closure.c index af3af0b..4750c6d 100644 --- a/src/closure.c +++ b/src/closure.c @@ -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 */ diff --git a/src/dvdisaster.c b/src/dvdisaster.c index eb6c4ac..e610af6 100644 --- a/src/dvdisaster.c +++ b/src/dvdisaster.c @@ -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; diff --git a/src/dvdisaster.h b/src/dvdisaster.h index 5ec383c..e0edaca 100644 --- a/src/dvdisaster.h +++ b/src/dvdisaster.h @@ -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); diff --git a/src/galois.c b/src/galois.c index a87aa5c..f783aa6 100644 --- a/src/galois.c +++ b/src/galois.c @@ -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; diff --git a/src/misc.c b/src/misc.c index 008ac7f..3bb61ee 100644 --- a/src/misc.c +++ b/src/misc.c @@ -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); } /* diff --git a/src/raw-sector-cache.c b/src/raw-sector-cache.c index db15184..b54759e 100644 --- a/src/raw-sector-cache.c +++ b/src/raw-sector-cache.c @@ -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; inSectors; 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; inSectors; 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)); diff --git a/src/read-adaptive-window.c b/src/read-adaptive-window.c index 481ece3..bb3722b 100644 --- a/src/read-adaptive-window.c +++ b/src/read-adaptive-window.c @@ -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, diff --git a/src/rs01-common.c b/src/rs01-common.c index 8c8200a..cdbab30 100644 --- a/src/rs01-common.c +++ b/src/rs01-common.c @@ -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); } diff --git a/src/rs01-verify.c b/src/rs01-verify.c index 6baeb26..dbd1f19 100644 --- a/src/rs01-verify.c +++ b/src/rs01-verify.c @@ -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, "%" PRId64 "", Closure->redMarkup, totalMissing); diff --git a/src/rs02-common.c b/src/rs02-common.c index 75b0280..7fe1028 100644 --- a/src/rs02-common.c +++ b/src/rs02-common.c @@ -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; diff --git a/src/rs02-verify.c b/src/rs02-verify.c index afc993d..49e3b40 100644 --- a/src/rs02-verify.c +++ b/src/rs02-verify.c @@ -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; diff --git a/src/rs03-common.c b/src/rs03-common.c index 266e9e3..f613f1f 100644 --- a/src/rs03-common.c +++ b/src/rs03-common.c @@ -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)); diff --git a/src/rs03-verify.c b/src/rs03-verify.c index abc2c5c..30adb42 100644 --- a/src/rs03-verify.c +++ b/src/rs03-verify.c @@ -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; diff --git a/src/scsi-layer.c b/src/scsi-layer.c index 95e6c7a..c56a0a4 100644 --- a/src/scsi-layer.c +++ b/src/scsi-layer.c @@ -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) diff --git a/src/udf.c b/src/udf.c index d462057..7c6e7b2 100644 --- a/src/udf.c +++ b/src/udf.c @@ -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");