[GRASS-SVN] r73983 - in grass/trunk/lib: imagery raster3d
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jan 20 08:30:12 PST 2019
Author: marisn
Date: 2019-01-20 08:30:12 -0800 (Sun, 20 Jan 2019)
New Revision: 73983
Modified:
grass/trunk/lib/imagery/sigset.c
grass/trunk/lib/raster3d/rle.c
Log:
Check for return value of scanf
Modified: grass/trunk/lib/imagery/sigset.c
===================================================================
--- grass/trunk/lib/imagery/sigset.c 2019-01-20 16:10:39 UTC (rev 73982)
+++ grass/trunk/lib/imagery/sigset.c 2019-01-20 16:30:12 UTC (rev 73983)
@@ -129,11 +129,14 @@
while (gettag(fd, tag)) {
if (eq(tag, "title:"))
- get_title(fd, S);
+ if (get_title(fd, S) != 0)
+ return -1;
if (eq(tag, "nbands:"))
- get_nbands(fd, S);
+ if (get_nbands(fd, S) != 0)
+ return -1;
if (eq(tag, "class:"))
- get_class(fd, S);
+ if (get_class(fd, S) != 0)
+ return -1;
}
return 1; /* for now assume success */
}
@@ -148,7 +151,8 @@
static int get_nbands(FILE * fd, struct SigSet *S)
{
- fscanf(fd, "%d", &S->nbands);
+ if (fscanf(fd, "%d", &S->nbands) != 1)
+ return -1;
return 0;
}
@@ -158,7 +162,8 @@
char title[1024];
*title = 0;
- fscanf(fd, "%[^\n]", title);
+ if (fscanf(fd, "%[^\n]", title) != 1)
+ return -1;
I_SetSigTitle(S, title);
return 0;
@@ -174,13 +179,17 @@
if (eq(tag, "endclass:"))
break;
if (eq(tag, "classnum:"))
- get_classnum(fd, C);
+ if (get_classnum(fd, C) != 0)
+ return -1;
if (eq(tag, "classtype:"))
- get_classtype(fd, C);
+ if (get_classtype(fd, C) != 0)
+ return -1;
if (eq(tag, "classtitle:"))
- get_classtitle(fd, C);
+ if (get_classtitle(fd, C) != 0)
+ return -1;
if (eq(tag, "subclass:"))
- get_subclass(fd, S, C);
+ if (get_subclass(fd, S, C) != 0)
+ return -1;
}
return 0;
@@ -188,7 +197,8 @@
static int get_classnum(FILE * fd, struct ClassSig *C)
{
- fscanf(fd, "%ld", &C->classnum);
+ if (fscanf(fd, "%ld", &C->classnum) != 1)
+ return -1;
return 0;
}
@@ -195,7 +205,8 @@
static int get_classtype(FILE * fd, struct ClassSig *C)
{
- fscanf(fd, "%d", &C->type);
+ if (fscanf(fd, "%d", &C->type) != 1)
+ return -1;
return 0;
}
@@ -205,7 +216,8 @@
char title[1024];
*title = 0;
- fscanf(fd, "%[^\n]", title);
+ if (fscanf(fd, "%[^\n]", title) != 1)
+ return -1;
I_SetClassTitle(C, title);
return 0;
@@ -222,11 +234,14 @@
if (eq(tag, "endsubclass:"))
break;
if (eq(tag, "pi:"))
- get_subclass_pi(fd, Sp);
+ if (get_subclass_pi(fd, Sp) != 0)
+ return -1;
if (eq(tag, "means:"))
- get_subclass_means(fd, Sp, S->nbands);
+ if (get_subclass_means(fd, Sp, S->nbands) != 0)
+ return -1;
if (eq(tag, "covar:"))
- get_subclass_covar(fd, Sp, S->nbands);
+ if (get_subclass_covar(fd, Sp, S->nbands) != 0)
+ return -1;
}
return 0;
@@ -234,7 +249,8 @@
static int get_subclass_pi(FILE * fd, struct SubSig *Sp)
{
- fscanf(fd, "%lf", &Sp->pi);
+ if (fscanf(fd, "%lf", &Sp->pi) != 1)
+ return -1;
return 0;
}
@@ -244,7 +260,8 @@
int i;
for (i = 0; i < nbands; i++)
- fscanf(fd, "%lf", &Sp->means[i]);
+ if (fscanf(fd, "%lf", &Sp->means[i]) != 1)
+ return -1;
return 0;
}
@@ -255,7 +272,8 @@
for (i = 0; i < nbands; i++)
for (j = 0; j < nbands; j++)
- fscanf(fd, "%lf", &Sp->R[i][j]);
+ if (fscanf(fd, "%lf", &Sp->R[i][j]) != 1)
+ return -1;
return 0;
}
Modified: grass/trunk/lib/raster3d/rle.c
===================================================================
--- grass/trunk/lib/raster3d/rle.c 2019-01-20 16:10:39 UTC (rev 73982)
+++ grass/trunk/lib/raster3d/rle.c 2019-01-20 16:30:12 UTC (rev 73983)
@@ -264,6 +264,10 @@
/*---------------------------------------------------------------------------*/
+/* TODO: Find out if this function used at all.
+ * Seems to be some leftover from the early pre-SVN days of GRASS GIS.
+ * Maris, 2018.
+ */
void test_rle()
{
char c[100];
@@ -271,7 +275,8 @@
do {
printf("length? ");
- scanf("%d", &length);
+ if (scanf("%d", &length) != 1)
+ Rast3d_fatal_error("Error reading length");
printf("length = %d\n", length);
printf("codeLength %d ", G_rle_codeLength(length));
(void)rle_length2code(length, c);
More information about the grass-commit
mailing list