Skip to content

Commit 2b64f2f

Browse files
committed
Fixed valgrind warning in field management functions.
1 parent 2160152 commit 2b64f2f

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/field.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* This file part of: SCAMP
99
*
10-
* Copyright: (C) 2002-2016 IAP/CNRS/UPMC
10+
* Copyright: (C) 2002-2017 IAP/CNRS/UPMC
1111
*
1212
* License: GNU General Public License
1313
*
@@ -22,7 +22,7 @@
2222
* You should have received a copy of the GNU General Public License
2323
* along with SCAMP. If not, see <http://www.gnu.org/licenses/>.
2424
*
25-
* Last modified: 23/03/2016
25+
* Last modified: 11/11/2017
2626
*
2727
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
2828

@@ -137,9 +137,6 @@ fieldstruct *load_field(char *filename, int fieldindex, char *hfilename)
137137
*pstr = '\0';
138138

139139
/* Identify image headers in catalog */
140-
tab = cat->tab;
141-
set = field->set;
142-
143140
/* Complete primary HDU first */
144141
field->headflag |= !read_aschead(prefs.ahead_global, 0, cat->tab);
145142
field->headflag |= !read_aschead(field->hfilename, 0, cat->tab);
@@ -186,6 +183,8 @@ fieldstruct *load_field(char *filename, int fieldindex, char *hfilename)
186183
n = 0;
187184

188185
/* Now scan other HDUs */
186+
tab = cat->tab;
187+
set = field->set;
189188
for (i=cat->ntab; i--; tab=tab->nexttab)
190189
if ((!strcmp("LDAC_IMHEAD",tab->extname))
191190
&& (key=read_key(tab, "Field Header Card")))
@@ -241,6 +240,10 @@ fieldstruct *load_field(char *filename, int fieldindex, char *hfilename)
241240
error(EXIT_FAILURE,"*Error*: No SExtractor FITS-LDAC header found in ",
242241
rfilename);
243242

243+
/* Save some memory */
244+
QREALLOC(field->set, setstruct *, field->nset);
245+
set = field->set;
246+
244247
if (field->cplot_colour<0 || field->cplot_colour>15)
245248
warning("CHECKPLOT field colour out of range, defaulted to ", "15");
246249

@@ -356,7 +359,8 @@ fieldstruct *load_field(char *filename, int fieldindex, char *hfilename)
356359
nsample += set[n]->nsample;
357360
free_tab(set[n]->imatab);
358361
set[n]->imatab = NULL;
359-
set[n]->setindex = n++;
362+
set[n]->setindex = n;
363+
n++;
360364
}
361365

362366
field->nsample = nsample;
@@ -380,7 +384,7 @@ INPUT Pointer to field structure.
380384
OUTPUT A pointer to the created field structure.
381385
NOTES Global preferences are used.
382386
AUTHOR E. Bertin (IAP)
383-
VERSION 29/09/2012
387+
VERSION 11/11/2017
384388
*/
385389
void locate_field(fieldstruct *field)
386390
{
@@ -408,9 +412,9 @@ void locate_field(fieldstruct *field)
408412

409413
/* Go through each set */
410414
pset = field->set;
411-
set = *(pset++);
412-
for (s=nset; s--; set=*(pset++))
415+
for (s=nset; s--;)
413416
{
417+
set = *(pset++);
414418
wcs = set->wcs;
415419
lng = wcs->lng;
416420
lat = wcs->lat;
@@ -454,9 +458,9 @@ void locate_field(fieldstruct *field)
454458
= -(airmassmin = expotimemin = epochmin = BIG);
455459
nairmass = nexpotime = nepoch = 0;
456460
pset = field->set;
457-
set=*(pset++);
458-
for (s=nset; s--; set=*(pset++))
461+
for (s=nset; s--;)
459462
{
463+
set=*(pset++);
460464
/*-- The distance is the distance to the center + the diagonal of the image */
461465
dist = wcs_dist(set->wcs, set->wcspos, field->meanwcspos) + set->radius;
462466
if (dist>maxradius)

0 commit comments

Comments
 (0)