[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master d6b4d9c: Return value of asprintf now checked
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master d6b4d9c: Return value of asprintf now checked |
Date: |
Sun, 28 Jan 2018 19:42:28 -0500 (EST) |
branch: master
commit d6b4d9cd37f7fbe8ae6b404ea7f6d752f7490891
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Return value of asprintf now checked
When `asprintf' is unable to allocate the necessary memory, it will return
a value that is less than zero. To avoid hard-to-debug errors, a check was
added to every call of `asprintf' so if this happens, the calling program
aborts.
This check was motivated by "ignoring return value of 'asprintf', declared
with attribute warn_unused_result" compiler warnings that came up on some
systems (debian package builders and also reported by Éric Thiébaut).
This fixes bug #52979.
---
THANKS | 1 +
bin/buildprog/buildprog.c | 53 +++++++++------
bin/convertt/jpeg.c | 3 +-
bin/convertt/ui.c | 3 +-
bin/crop/crop.c | 34 ++++++----
bin/crop/onecrop.c | 10 +--
bin/crop/ui.c | 15 +++--
bin/fits/fits.c | 3 +-
bin/mkcatalog/mkcatalog.c | 147 ++++++++++++++++++++++++++---------------
bin/mkcatalog/ui.c | 28 +++++---
bin/mkprof/mkprof.c | 17 +++--
bin/mkprof/ui.c | 43 ++++++++----
bin/noisechisel/clumps.c | 5 +-
bin/noisechisel/detection.c | 52 ++++++++++-----
bin/noisechisel/segmentation.c | 54 +++++++++------
bin/noisechisel/threshold.c | 5 +-
bin/noisechisel/ui.c | 12 +++-
bin/statistics/sky.c | 5 +-
bin/statistics/statistics.c | 35 +++++++---
bin/statistics/ui.c | 15 ++++-
doc/announce-acknowledge.txt | 1 +
lib/blank.c | 132 ++++++++++++++++++++++++++++++------
lib/checkset.c | 5 +-
lib/data.c | 12 +++-
lib/fits.c | 44 ++++++++----
lib/options.c | 51 ++++++++------
lib/table.c | 12 ++--
lib/tableintern.c | 8 ++-
lib/txt.c | 3 +-
lib/type.c | 20 ++++--
30 files changed, 572 insertions(+), 256 deletions(-)
diff --git a/THANKS b/THANKS
index 1162539..79561bf 100644
--- a/THANKS
+++ b/THANKS
@@ -46,6 +46,7 @@ support in Gnuastro. The list is ordered alphabetically (by
family name).
Richard Stallman address@hidden
Ole Streicher address@hidden
Alfred M. Szmidt address@hidden
+ Éric Thiébaut address@hidden
Ignacio Trujillo address@hidden
David Valls-Gabaud address@hidden
Christopher Willmer address@hidden
diff --git a/bin/buildprog/buildprog.c b/bin/buildprog/buildprog.c
index a2b3b75..79beb3f 100644
--- a/bin/buildprog/buildprog.c
+++ b/bin/buildprog/buildprog.c
@@ -88,30 +88,37 @@ buildprog(struct buildprogparams *p)
}
/* Compiler options with values: */
- if(p->warning) asprintf(&warning, "-W%s", p->warning);
- if(p->optimize) asprintf(&optimize, "-O%s", p->optimize);
+ if(p->warning)
+ if( asprintf(&warning, "-W%s", p->warning)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ if(p->optimize)
+ if( asprintf(&optimize, "-O%s", p->optimize)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
/* Libtool `.la' file: */
if(p->la) fullla=p->la;
- else asprintf(&fullla, "%s/libgnuastro.la", LIBDIR);
+ else
+ if( asprintf(&fullla, "%s/libgnuastro.la", LIBDIR)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
/* Put the command to run into a string. */
- asprintf(&command, "%s %s %s%s --mode=link gcc %s %s %s %s %s %s %s "
- "-I%s %s -o %s",
- GAL_CONFIG_GNULIBTOOL_EXEC,
- p->cp.quiet ? "--quiet" : "",
- p->tag ? "--tag=" : "",
- p->tag ? p->tag : "",
- warning ? warning : "",
- p->debug ? "-g" : "",
- optimize ? optimize : "",
- include ? include : "",
- linkdir ? linkdir : "",
- p->sourceargs->v,
- linklib ?linklib : "",
- INCLUDEDIR,
- fullla,
- p->cp.output);
+ if( asprintf(&command, "%s %s %s%s --mode=link gcc %s %s %s %s %s %s %s "
+ "-I%s %s -o %s",
+ GAL_CONFIG_GNULIBTOOL_EXEC,
+ p->cp.quiet ? "--quiet" : "",
+ p->tag ? "--tag=" : "",
+ p->tag ? p->tag : "",
+ warning ? warning : "",
+ p->debug ? "-g" : "",
+ optimize ? optimize : "",
+ include ? include : "",
+ linkdir ? linkdir : "",
+ p->sourceargs->v,
+ linklib ?linklib : "",
+ INCLUDEDIR,
+ fullla,
+ p->cp.output)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
/* Compile (and link): */
retval=system(command);
@@ -129,11 +136,15 @@ buildprog(struct buildprogparams *p)
{
case '.':
case '/':
- asprintf(&command, "%s %s", p->cp.output, arguments?arguments:"");
+ if( asprintf(&command, "%s %s", p->cp.output,
+ arguments?arguments:"")<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
break;
default:
- asprintf(&command, "./%s %s", p->cp.output, arguments?arguments:"");
+ if( asprintf(&command, "./%s %s", p->cp.output,
+ arguments?arguments:"")<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
}
/* Print the executed command if necessary, then run it. */
diff --git a/bin/convertt/jpeg.c b/bin/convertt/jpeg.c
index b67563c..dd8989b 100644
--- a/bin/convertt/jpeg.c
+++ b/bin/convertt/jpeg.c
@@ -261,7 +261,8 @@ jpeg_read_to_ll(char *filename, gal_data_t **list, size_t
minmapsize)
{
dsize[0]=s0;
dsize[1]=s1;
- asprintf(&name, "JPEG_CH_%zu", i+1);
+ if( asprintf(&name, "JPEG_CH_%zu", i+1)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_data_add_alloc(list, allcolors[i], GAL_TYPE_UINT8, ndim,
dsize, NULL, 0, minmapsize, name, NULL, NULL);
free(name);
diff --git a/bin/convertt/ui.c b/bin/convertt/ui.c
index e21439d..e6a7aec 100644
--- a/bin/convertt/ui.c
+++ b/bin/convertt/ui.c
@@ -614,7 +614,8 @@ ui_add_dot_use_automatic_output(struct converttparams *p)
/* If the suffix does not start with a `.', put one there. */
if(suffix[0]!='.')
{
- asprintf(&tmp, ".%s", suffix);
+ if( asprintf(&tmp, ".%s", suffix)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
free(suffix);
suffix=tmp;
}
diff --git a/bin/crop/crop.c b/bin/crop/crop.c
index 6e72dcd..9bcf737 100644
--- a/bin/crop/crop.c
+++ b/bin/crop/crop.c
@@ -67,12 +67,19 @@ crop_verbose_info(struct onecropparams *crp)
/* Define the output string based on the length of the output file. */
if ( outnamelen > FILENAME_BUFFER_IN_VERB )
- asprintf(&msg, "...%s %s: %zu input%s.",
- &crp->name[ outnamelen - FILENAME_BUFFER_IN_VERB + 3 ],
- filestatus, crp->numimg, crp->numimg==1 ? "" :"s");
+ {
+ if( asprintf(&msg, "...%s %s: %zu input%s.",
+ &crp->name[ outnamelen - FILENAME_BUFFER_IN_VERB + 3 ],
+ filestatus, crp->numimg, crp->numimg==1 ? "" :"s")<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
else
- asprintf(&msg, "%-*s %s: %zu input%s.", FILENAME_BUFFER_IN_VERB,
- crp->name, filestatus, crp->numimg, crp->numimg==1 ? "" : "s");
+ {
+ if( asprintf(&msg, "%-*s %s: %zu input%s.", FILENAME_BUFFER_IN_VERB,
+ crp->name, filestatus, crp->numimg,
+ crp->numimg==1 ? "" : "s")<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
/* Print the results. */
gal_timing_report(NULL, msg, 2);
@@ -120,15 +127,16 @@ crop_verbose_final(struct cropparams *p)
}
/* Print the basic information. */
- asprintf(&msg, "%zu crops created.", numcrops);
+ if( asprintf(&msg, "%zu crops created.", numcrops)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(NULL, msg, 1);
free(msg);
/* Only if the user wanted to check the center. */
if(p->checkcenter)
{
- asprintf(&msg, "%zu filled in the center.",
- numcfilled);
+ if( asprintf(&msg, "%zu filled in the center.", numcfilled)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(NULL, msg, 1);
free(msg);
}
@@ -136,8 +144,9 @@ crop_verbose_final(struct cropparams *p)
/* Only if there were stitched images. */
if(numstitched)
{
- asprintf(&msg, "%zu crops used more than one input.",
- numstitched);
+ if( asprintf(&msg, "%zu crops used more than one input.",
+ numstitched)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(NULL, msg, 1);
free(msg);
}
@@ -460,8 +469,9 @@ crop(struct cropparams *p)
{
if(p->checkcenter)
{
- asprintf(&tmp, "Width of central check box: %zu",
- p->checkcenter);
+ if( asprintf(&tmp, "Width of central check box: %zu",
+ p->checkcenter)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, tmp, 0);
}
gal_checkset_writable_remove(LOGFILENAME, 0, p->cp.dontdelete);
diff --git a/bin/crop/onecrop.c b/bin/crop/onecrop.c
index 7c99f3d..93cbdea 100644
--- a/bin/crop/onecrop.c
+++ b/bin/crop/onecrop.c
@@ -449,12 +449,14 @@ onecrop_name(struct onecropparams *crp)
if(p->name)
{
strarr=p->name;
- asprintf(&crp->name, "%s%s%s", cp->output, strarr[crp->out_ind],
- p->suffix);
+ if( asprintf(&crp->name, "%s%s%s", cp->output, strarr[crp->out_ind],
+ p->suffix)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
}
else
- asprintf(&crp->name, "%s%zu%s", cp->output, crp->out_ind+1,
- p->suffix);
+ if( asprintf(&crp->name, "%s%zu%s", cp->output, crp->out_ind+1,
+ p->suffix)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
/* Make sure the file doesn't exist. */
gal_checkset_writable_remove(crp->name, 0, cp->dontdelete);
diff --git a/bin/crop/ui.c b/bin/crop/ui.c
index cb83e77..ffd6a4b 100644
--- a/bin/crop/ui.c
+++ b/bin/crop/ui.c
@@ -727,8 +727,9 @@ ui_make_log(struct cropparams *p)
if(p->cp.log==0) return;
/* Column to specify if the central pixels are filled. */
- asprintf(&comment, "Are the central pixels filled? (1: yes, 0: no, "
- "%u: not checked)", GAL_BLANK_UINT8);
+ if( asprintf(&comment, "Are the central pixels filled? (1: yes, 0: no, "
+ "%u: not checked)", GAL_BLANK_UINT8)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_data_add_alloc(&p->log, NULL, GAL_TYPE_UINT8, 1, &p->numout,
NULL, 1, p->cp.minmapsize, "CENTER_FILLED",
"bool", comment);
@@ -953,13 +954,15 @@ ui_read_check_inputs_setup(int argc, char *argv[], struct
cropparams *p)
if(!p->cp.quiet)
{
printf(PROGRAM_NAME" started on %s", ctime(&p->rawtime));
- asprintf(&msg, "Read metadata of %zu dataset%s.", p->numin,
- p->numin>1 ? "s" : "");
+ if( asprintf(&msg, "Read metadata of %zu dataset%s.", p->numin,
+ p->numin>1 ? "s" : "")<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(&t1, msg, 1);
if(p->numout>1)
{
- asprintf(&msg, "Will try making %zu crops (from catalog).",
- p->numout);
+ if( asprintf(&msg, "Will try making %zu crops (from catalog).",
+ p->numout)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(NULL, msg, 1);
}
}
diff --git a/bin/fits/fits.c b/bin/fits/fits.c
index 3ed3135..b836dd4 100644
--- a/bin/fits/fits.c
+++ b/bin/fits/fits.c
@@ -213,7 +213,8 @@ fits_print_extension_info(struct fitsparams *p)
/* Move to the next extension if we aren't on the last extension. */
if( i!=numext-1 && fits_movrel_hdu(fptr, 1, &hdutype, &status) )
{
- asprintf(&msg, "moving to hdu %zu", i+1);
+ if( asprintf(&msg, "moving to hdu %zu", i+1)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_fits_io_error(status, msg);
}
}
diff --git a/bin/mkcatalog/mkcatalog.c b/bin/mkcatalog/mkcatalog.c
index bc35f3b..08cdded 100644
--- a/bin/mkcatalog/mkcatalog.c
+++ b/bin/mkcatalog/mkcatalog.c
@@ -660,59 +660,70 @@ mkcatalog_outputs_same_start(struct mkcatalogparams *p,
int o0c1,
char *clumpsfile=p->clumpsfile ? p->clumpsfile : p->inputname;
char *objectsfile=p->objectsfile ? p->objectsfile : p->inputname;
- asprintf(&str, "%s catalog of %s", o0c1 ? "Object" : "Clump",
- PROGRAM_STRING);
+ if( asprintf(&str, "%s catalog of %s", o0c1 ? "Object" : "Clump",
+ PROGRAM_STRING)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
/* If in a Git controlled directory and output isn't a FITS file (in
FITS, this will be automatically included). */
if(p->cp.tableformat==GAL_TABLE_FORMAT_TXT && gal_git_describe())
{
- asprintf(&str, "Working directory commit %s", gal_git_describe());
+ if(asprintf(&str, "Working directory commit %s", gal_git_describe())<0)
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
/* Write the date. However, `ctime' is going to put a new-line character
in the end of its string, so we are going to remove it manually. */
- asprintf(&str, "%s started on %s", PROGRAM_NAME, ctime(&p->rawtime));
+ if( asprintf(&str, "%s started on %s", PROGRAM_NAME, ctime(&p->rawtime))<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
str[strlen(str)-1]='\0';
gal_list_str_add(&comments, str, 0);
if(p->cp.tableformat==GAL_TABLE_FORMAT_TXT)
{
- asprintf(&str, "--------- Input files ---------");
+ if( asprintf(&str, "--------- Input files ---------")<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
- asprintf(&str, "Values: %s (hdu: %s).", p->inputname, p->cp.hdu);
+ if( asprintf(&str, "Values: %s (hdu: %s).", p->inputname, p->cp.hdu)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
- asprintf(&str, "Objects: %s (hdu: %s).", objectsfile, p->objectshdu);
+ if( asprintf(&str, "Objects: %s (hdu: %s).", objectsfile, p->objectshdu)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
if(p->clumps)
{
- asprintf(&str, "Clumps: %s (hdu: %s).", clumpsfile, p->clumpshdu);
+ if(asprintf(&str, "Clumps: %s (hdu: %s).", clumpsfile, p->clumpshdu)<0)
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
- asprintf(&str, "Sky: %s (hdu: %s).", skyfile, p->skyhdu);
+ if( asprintf(&str, "Sky: %s (hdu: %s).", skyfile, p->skyhdu)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
- asprintf(&str, "Sky STD: %s (hdu: %s).", stdfile, p->stdhdu);
+ if( asprintf(&str, "Sky STD: %s (hdu: %s).", stdfile, p->stdhdu)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
if(p->upmaskfile)
{
- asprintf(&str, "Upperlimit mask: %s (hdu: %s).", p->upmaskfile,
- p->upmaskhdu);
+ if( asprintf(&str, "Upperlimit mask: %s (hdu: %s).", p->upmaskfile,
+ p->upmaskhdu)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
if(p->cp.tableformat==GAL_TABLE_FORMAT_TXT)
{
- asprintf(&str, "--------- Supplimentary information ---------");
+ if( asprintf(&str, "--------- Supplimentary information ---------")<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
@@ -721,14 +732,16 @@ mkcatalog_outputs_same_start(struct mkcatalogparams *p,
int o0c1,
pixarea=gal_wcs_pixel_area_arcsec2(p->input->wcs);
if( isnan(pixarea)==0 )
{
- asprintf(&str, "Pixel area (arcsec^2): %g", pixarea);
+ if( asprintf(&str, "Pixel area (arcsec^2): %g", pixarea)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
}
if(p->hasmag)
{
- asprintf(&str, "Zeropoint magnitude: %.4f", p->zeropoint);
+ if( asprintf(&str, "Zeropoint magnitude: %.4f", p->zeropoint)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
@@ -736,15 +749,16 @@ mkcatalog_outputs_same_start(struct mkcatalogparams *p,
int o0c1,
if( !isnan(p->zeropoint) && !isnan(p->sfmagnsigma) )
{
/* Per pixel. */
- asprintf(&str, "%g sigma surface brightness (magnitude/pixel): %.3f",
- p->sfmagnsigma, ( -2.5f
- *log10( p->sfmagnsigma
- * p->medstd )
- + p->zeropoint ) );
+ if( asprintf(&str, "%g sigma surface brightness (magnitude/pixel): "
+ "%.3f", p->sfmagnsigma, ( -2.5f
+ *log10( p->sfmagnsigma
+ * p->medstd )
+ + p->zeropoint ) )<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
- /* Per requested projected area: if a pixel area could be measured (a
- WCS was given), then also estimate the surface brightness over one
+ /* Requested projected area: if a pixel area could be measured (a WCS
+ was given), then also estimate the surface brightness over one
arcsecond^2. From the pixel area, we know how many pixels are
necessary to fill the requested projected area (in
arcsecond^2). We also know that as the number of samples (pixels)
@@ -753,14 +767,19 @@ mkcatalog_outputs_same_start(struct mkcatalogparams *p,
int o0c1,
if(!isnan(pixarea) && !isnan(p->sfmagarea))
{
/* Prepare the comment/information. */
- if(p->sfmagarea==1.0f) tstr=NULL;
- else asprintf(&tstr, "%g-", p->sfmagarea);
- asprintf(&str, "%g sigma surface brightness (magnitude/%sarcsec^2): "
- "%.3f", p->sfmagnsigma, tstr ? tstr : "",
- ( -2.5f * log10( p->sfmagnsigma
- * p->medstd
- * sqrt( p->sfmagarea / pixarea) )
- + p->zeropoint ) );
+ if(p->sfmagarea==1.0f)
+ tstr=NULL;
+ else
+ if( asprintf(&tstr, "%g-", p->sfmagarea)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ if( asprintf(&str, "%g sigma surface brightness "
+ "(magnitude/%sarcsec^2): %.3f", p->sfmagnsigma,
+ tstr ? tstr : "",
+ ( -2.5f * log10( p->sfmagnsigma
+ * p->medstd
+ * sqrt( p->sfmagarea / pixarea) )
+ + p->zeropoint ) )<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
/* Add the final string/line to the catalog comments. */
gal_list_str_add(&comments, str, 0);
@@ -774,36 +793,42 @@ mkcatalog_outputs_same_start(struct mkcatalogparams *p,
int o0c1,
}
/* Notice: */
- asprintf(&str, "Pixel STD for surface brightness calculation%s: %f",
- (!isnan(pixarea) && !isnan(p->sfmagarea))?"s":"", p->medstd);
+ if( asprintf(&str, "Pixel STD for surface brightness calculation%s: %f",
+ (!isnan(pixarea) && !isnan(p->sfmagarea))?"s":"",
+ p->medstd)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
snlim = o0c1 ? p->clumpsn : p->detsn;
if( !isnan(snlim) )
{
- asprintf(&str, "%s limiting signal-to-noise ratio: %.3f", ObjClump,
- snlim);
+ if( asprintf(&str, "%s limiting signal-to-noise ratio: %.3f", ObjClump,
+ snlim)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
if(o0c1==0)
{
- asprintf(&str, "(NOTE: S/N limit above is for pseudo-detections, "
- "not objects.)");
+ if( asprintf(&str, "(NOTE: S/N limit above is for pseudo-detections, "
+ "not objects.)")<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
if(p->cpscorr>1.0f)
{
- asprintf(&str, "Counts-per-second correction: %.3f", p->cpscorr);
+ if( asprintf(&str, "Counts-per-second correction: %.3f", p->cpscorr)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
if( !isnan(p->threshold) )
{
- asprintf(&str, "**IMPORTANT** Pixel threshold (multiple of local "
- "std): %.3f", p->threshold);
+ if( asprintf(&str, "**IMPORTANT** Pixel threshold (multiple of local "
+ "std): %.3f", p->threshold)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
@@ -812,40 +837,53 @@ mkcatalog_outputs_same_start(struct mkcatalogparams *p,
int o0c1,
{
if(p->cp.tableformat==GAL_TABLE_FORMAT_TXT)
{
- asprintf(&str, "--------- Upper-limit measurement ---------");
+ if(asprintf(&str, "--------- Upper-limit measurement ---------")<0)
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
- asprintf(&str, "Number of random samples: %zu", p->upnum);
+ if( asprintf(&str, "Number of random samples: %zu", p->upnum)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
if(p->uprange)
{
- asprintf(&str, "Range of random samples about target: %zu, %zu",
- p->uprange[1], p->uprange[0]);
+ if( asprintf(&str, "Range of random samples about target: %zu, %zu",
+ p->uprange[1], p->uprange[0])<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
- asprintf(&str, "Random number generator name: %s", p->rngname);
+ if( asprintf(&str, "Random number generator name: %s", p->rngname)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
- asprintf(&str, "Random number generator seed: %"PRIu64, p->seed);
+ if( asprintf(&str, "Random number generator seed: %"PRIu64, p->seed)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
- asprintf(&str, "Multiple of STD used for sigma-clipping: %.3f",
- p->upsigmaclip[0]);
+ if( asprintf(&str, "Multiple of STD used for sigma-clipping: %.3f",
+ p->upsigmaclip[0])<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
if(p->upsigmaclip[1]>=1.0f)
- asprintf(&str, "Number of clips for sigma-clipping: %.0f",
- p->upsigmaclip[1]);
+ {
+ if( asprintf(&str, "Number of clips for sigma-clipping: %.0f",
+ p->upsigmaclip[1])<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
else
- asprintf(&str, "Tolerance level to sigma-clipping: %.3f",
- p->upsigmaclip[1]);
+ {
+ if( asprintf(&str, "Tolerance level to sigma-clipping: %.3f",
+ p->upsigmaclip[1])<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
gal_list_str_add(&comments, str, 0);
- asprintf(&str, "Multiple of sigma-clipped STD for upper-limit: %.3f",
- p->upnsigma);
+ if( asprintf(&str, "Multiple of sigma-clipped STD for upper-limit: "
+ "%.3f", p->upnsigma)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
@@ -853,7 +891,8 @@ mkcatalog_outputs_same_start(struct mkcatalogparams *p, int
o0c1,
if(p->cp.tableformat==GAL_TABLE_FORMAT_TXT)
{
- asprintf(&str, "--------- Table columns ---------");
+ if( asprintf(&str, "--------- Table columns ---------")<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
}
diff --git a/bin/mkcatalog/ui.c b/bin/mkcatalog/ui.c
index 9266f4e..aaf192a 100644
--- a/bin/mkcatalog/ui.c
+++ b/bin/mkcatalog/ui.c
@@ -495,15 +495,21 @@ ui_preparations_read_inputs(struct mkcatalogparams *p)
|| p->clumps->type==GAL_TYPE_FLOAT64 ) ) )
{
if(p->clumps)
- asprintf(&namestypes, "However, `%s' (hdu: %s) and `%s' (hdu: %s) "
- "have types of `%s' and `%s' respectively", objectsfile,
- p->objectshdu, clumpsfile, p->clumpshdu,
- gal_type_name(p->objects->type, 1),
- gal_type_name(p->clumps->type, 1) );
+ {
+ if( asprintf(&namestypes, "However, `%s' (hdu: %s) and `%s' "
+ "(hdu: %s) have types of `%s' and `%s' respectively",
+ objectsfile, p->objectshdu, clumpsfile, p->clumpshdu,
+ gal_type_name(p->objects->type, 1),
+ gal_type_name(p->clumps->type, 1) )<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
else
- asprintf(&namestypes, "However, %s (hdu: %s) has a type of %s",
- objectsfile, p->objectshdu,
- gal_type_name(p->objects->type, 1));
+ {
+ if( asprintf(&namestypes, "However, %s (hdu: %s) has a type of %s",
+ objectsfile, p->objectshdu,
+ gal_type_name(p->objects->type, 1))<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
error(EXIT_FAILURE, 0, "labeled images (for objects or clumps) must "
"have an integer datatype. %s.\n\n"
"If you are sure the images contain only integer values but "
@@ -607,8 +613,10 @@ ui_preparations_read_keywords(struct mkcatalogparams *p)
if(keys[0].status) p->clumpsn=NAN;
if(keys[1].status)
{
- asprintf(&msg, "couldn't find/read NUMLABS in the header of "
- "%s (hdu: %s), see error above", clumpsfile, p->clumpshdu);
+ if( asprintf(&msg, "couldn't find/read NUMLABS in the header of "
+ "%s (hdu: %s), see error above", clumpsfile,
+ p->clumpshdu)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_fits_io_error(keys[1].status, msg);
}
}
diff --git a/bin/mkprof/mkprof.c b/bin/mkprof/mkprof.c
index 2e08033..0abc74c 100644
--- a/bin/mkprof/mkprof.c
+++ b/bin/mkprof/mkprof.c
@@ -138,7 +138,8 @@ saveindividual(struct mkonthread *mkp)
filename=p->mergedimgname;
else
{
- asprintf(&filename, "%s%zu_%s", outdir, ibq->id, p->basename);
+ if( asprintf(&filename, "%s%zu_%s", outdir, ibq->id, p->basename)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_checkset_writable_remove(filename, 0, p->cp.dontdelete);
}
@@ -166,7 +167,8 @@ saveindividual(struct mkonthread *mkp)
/* Report if in verbose mode. */
if(!p->cp.quiet)
{
- asprintf(&jobname, "%s created.", filename);
+ if( asprintf(&jobname, "%s created.", filename)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(NULL, jobname, 2);
free(jobname);
}
@@ -537,8 +539,9 @@ mkprof_write(struct mkprofparams *p)
++complete;
if(!p->cp.quiet && p->num>1)
{
- asprintf(&jobname, "row %zu complete, %zu left to go",
- ibq->id+1, num-complete);
+ if( asprintf(&jobname, "row %zu complete, %zu left to go",
+ ibq->id+1, num-complete)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(NULL, jobname, 2);
free(jobname);
}
@@ -577,7 +580,8 @@ mkprof_write(struct mkprofparams *p)
/* In verbose mode, print the information. */
if(!p->cp.quiet)
{
- asprintf(&jobname, "%s created.", p->mergedimgname);
+ if( asprintf(&jobname, "%s created.", p->mergedimgname)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(&t1, jobname, 1);
free(jobname);
}
@@ -701,7 +705,8 @@ mkprof(struct mkprofparams *p)
/* Write the log file. */
if(p->cp.log)
{
- asprintf(&tmp, "Zeropoint: %g", p->zeropoint);
+ if( asprintf(&tmp, "Zeropoint: %g", p->zeropoint)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, tmp, 0);
gal_checkset_writable_remove(LOGFILENAME, 0, p->cp.dontdelete);
gal_table_write_log(p->log, PROGRAM_STRING, &p->rawtime, comments,
diff --git a/bin/mkprof/ui.c b/bin/mkprof/ui.c
index d048988..0381f0a 100644
--- a/bin/mkprof/ui.c
+++ b/bin/mkprof/ui.c
@@ -1316,7 +1316,8 @@ ui_make_log(struct mkprofparams *p)
/* Row number in input catalog. */
name=gal_fits_name_save_as_string(p->catname, p->cp.hdu);
- asprintf(&comment, "Row number of profile in %s.", name);
+ if( asprintf(&comment, "Row number of profile in %s.", name)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_data_add_alloc(&p->log, NULL, GAL_TYPE_UINT64, 1, &p->num, NULL,
1, p->cp.minmapsize, "INPUT_ROW_NO", "count",
comment);
@@ -1395,40 +1396,56 @@ ui_print_intro(struct mkprofparams *p)
printf(PROGRAM_NAME" started on %s", ctime(&p->rawtime));
if(p->kernel)
- asprintf(&jobname, "Building one %s kernel",
- ui_profile_name_write(p->kernel->status));
+ {
+ if( asprintf(&jobname, "Building one %s kernel",
+ ui_profile_name_write(p->kernel->status))<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
else
- asprintf(&jobname, "%zu profile%sread from %s", p->num,
- p->num>1?"s ":" ", p->catname);
+ {
+ if( asprintf(&jobname, "%zu profile%sread from %s", p->num,
+ p->num>1?"s ":" ", p->catname)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
gal_timing_report(NULL, jobname, 1);
free(jobname);
if(p->backname)
{
if(p->nomerged)
- asprintf(&jobname, "WCS information read from %s", p->backname);
+ {
+ if( asprintf(&jobname, "WCS information read from %s",
+ p->backname)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
else
- asprintf(&jobname, "%s is read and will be used as canvas",
- p->backname);
+ {
+ if( asprintf(&jobname, "%s is read and will be used as canvas",
+ p->backname)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
gal_timing_report(NULL, jobname, 1);
free(jobname);
}
- asprintf(&jobname, "Random number generator (RNG) type: %s",
- gsl_rng_name(p->rng));
+ if( asprintf(&jobname, "Random number generator (RNG) type: %s",
+ gsl_rng_name(p->rng))<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(NULL, jobname, 1);
free(jobname);
if(p->envseed)
{
- asprintf(&jobname, "RNG seed for all profiles: %lu",
- gsl_rng_default_seed);
+ if( asprintf(&jobname, "RNG seed for all profiles: %lu",
+ gsl_rng_default_seed)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(NULL, jobname, 1);
free(jobname);
}
if(p->kernel==NULL)
{
- asprintf(&jobname, "Using %zu threads.", p->cp.numthreads);
+ if( asprintf(&jobname, "Using %zu threads.", p->cp.numthreads)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(NULL, jobname, 1);
free(jobname);
}
diff --git a/bin/noisechisel/clumps.c b/bin/noisechisel/clumps.c
index e4a31c1..172f112 100644
--- a/bin/noisechisel/clumps.c
+++ b/bin/noisechisel/clumps.c
@@ -1377,8 +1377,9 @@ clumps_true_find_sn_thresh(struct noisechiselparams *p)
p->clumpsnthresh = *((float *)(quant->array));
if(!p->cp.quiet)
{
- asprintf(&msg, "Clump S/N: %.2f (%.3f quant of %zu).",
- p->clumpsnthresh, p->segquant, sn->size);
+ if( asprintf(&msg, "Clump S/N: %.2f (%.3f quant of %zu).",
+ p->clumpsnthresh, p->segquant, sn->size)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(&t1, msg, 2);
free(msg);
}
diff --git a/bin/noisechisel/detection.c b/bin/noisechisel/detection.c
index cc10709..93e2132 100644
--- a/bin/noisechisel/detection.c
+++ b/bin/noisechisel/detection.c
@@ -81,8 +81,9 @@ detection_initial(struct noisechiselparams *p)
gal_binary_erode(p->binary, p->erode, p->erodengb==4 ? 1 : 2, 1);
if(!p->cp.quiet)
{
- asprintf(&msg, "Eroded %zu time%s (%zu-connectivity).", p->erode,
- p->erode>1?"s":"", p->erodengb);
+ if( asprintf(&msg, "Eroded %zu time%s (%zu-connectivity).", p->erode,
+ p->erode>1?"s":"", p->erodengb)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(&t1, msg, 2);
free(msg);
}
@@ -104,8 +105,9 @@ detection_initial(struct noisechiselparams *p)
gal_binary_open(p->binary, p->opening, p->openingngb==4 ? 1 : 2, 1);
if(!p->cp.quiet)
{
- asprintf(&msg, "Opened (depth: %zu, %s connectivity).",
- p->opening, p->openingngb==4 ? "4" : "8");
+ if( asprintf(&msg, "Opened (depth: %zu, %s connectivity).",
+ p->opening, p->openingngb==4 ? "4" : "8")<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(&t1, msg, 2);
free(msg);
}
@@ -125,7 +127,9 @@ detection_initial(struct noisechiselparams *p)
/* Report the ending of initial detection. */
if(!p->cp.quiet)
{
- asprintf(&msg, "%zu initial detections found.", p->numinitialdets);
+ if( asprintf(&msg, "%zu initial detections found.",
+ p->numinitialdets)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(&t0, msg, 1);
free(msg);
}
@@ -408,9 +412,10 @@ detection_sn_write_to_file(struct noisechiselparams *p,
gal_data_t *sn,
gal_list_str_t *comments=NULL;
/* Comment for extension on further explanation. */
- asprintf(&str, "See also: `%s' HDU of output with "
- "`--checkdetection'", ( s0d1D2<2
- ? "PSEUDOS-FOR-SN": "DILATED" ));
+ if( asprintf(&str, "See also: `%s' HDU of output with "
+ "`--checkdetection'", ( s0d1D2<2
+ ? "PSEUDOS-FOR-SN": "DILATED" ))<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, str, 0);
@@ -726,8 +731,9 @@ detection_pseudo_real(struct noisechiselparams *p)
p->detsnthresh = *((float *)(quant->array));
if(!p->cp.quiet)
{
- asprintf(&msg, "Pseudo-det S/N: %.2f (%.2f quant of %zu).",
- p->detsnthresh, p->detquant, sn->size);
+ if( asprintf(&msg, "Pseudo-det S/N: %.2f (%.2f quant of %zu).",
+ p->detsnthresh, p->detquant, sn->size)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(&t1, msg, 2);
free(msg);
}
@@ -1044,8 +1050,9 @@ detection(struct noisechiselparams *p)
threshold_apply(p, p->sky->array, p->std->array, THRESHOLD_SKY_STD);
if(!p->cp.quiet)
{
- asprintf(&msg, "Pseudo-detection thresh (%.3f sigma) applied.",
- p->dthresh);
+ if( asprintf(&msg, "Pseudo-detection thresh (%.3f sigma) applied.",
+ p->dthresh)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(&t1, msg, 2);
free(msg);
}
@@ -1062,8 +1069,9 @@ detection(struct noisechiselparams *p)
num_true_initial=detection_remove_false_initial(p, workbin);
if(!p->cp.quiet)
{
- asprintf(&msg, "%zu false initial detections removed.",
- p->numinitialdets - num_true_initial);
+ if( asprintf(&msg, "%zu false initial detections removed.",
+ p->numinitialdets - num_true_initial)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(&t1, msg, 2);
free(msg);
}
@@ -1077,10 +1085,17 @@ detection(struct noisechiselparams *p)
if(!p->cp.quiet)
{
if(p->detgrowquant==1.0f)
- asprintf(&msg, "%zu detections with no growth.", num_true_initial);
+ {
+ if( asprintf(&msg, "%zu detections with no growth.",
+ num_true_initial)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
else
- asprintf(&msg, "%zu detections after growth to %.3f quantile.",
- num_true_initial, p->detgrowquant);
+ {
+ if( asprintf(&msg, "%zu detections after growth to %.3f quantile.",
+ num_true_initial, p->detgrowquant)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
gal_timing_report(&t1, msg, 2);
free(msg);
}
@@ -1098,7 +1113,8 @@ detection(struct noisechiselparams *p)
: num_true_initial );
if(!p->cp.quiet)
{
- asprintf(&msg, "%zu final true detections.", p->numdetections);
+ if( asprintf(&msg, "%zu final true detections.", p->numdetections)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(&t0, msg, 1);
free(msg);
}
diff --git a/bin/noisechisel/segmentation.c b/bin/noisechisel/segmentation.c
index 8737b50..3111a5b 100644
--- a/bin/noisechisel/segmentation.c
+++ b/bin/noisechisel/segmentation.c
@@ -593,8 +593,9 @@ segmentation_save_sn_table(struct clumps_params *clprm)
/* Write the comments. */
gal_list_str_add(&comments, "See also: `CLUMPS_ALL_DET' HDU of "
"output with `--checksegmentation'.", 1);
- asprintf(&msg, "S/N values of `nan': clumps smaller than `--segsnminarea' "
- "of %zu.", p->segsnminarea);
+ if( asprintf(&msg, "S/N values of `nan': clumps smaller than "
+ "`--segsnminarea' of %zu.", p->segsnminarea)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, msg, 0);
gal_list_str_add(&comments, "S/N of clumps over detected regions.", 1);
gal_table_comments_add_intro(&comments, PROGRAM_STRING, &p->rawtime);
@@ -687,8 +688,10 @@ segmentation_detections(struct noisechiselparams *p)
demo->name = "DET_CLUMPS_ALL";
if(!p->cp.quiet)
{
- asprintf(&msg, "Identified clumps over detections "
- "(HDU: `%s').", demo->name);
+ if( asprintf(&msg, "Identified clumps over detections "
+ "(HDU: `%s').", demo->name)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation",
+ __func__);
gal_timing_report(NULL, msg, 2);
free(msg);
}
@@ -699,8 +702,10 @@ segmentation_detections(struct noisechiselparams *p)
demo->name = "DET_CLUMPS_TRUE";
if(!p->cp.quiet)
{
- asprintf(&msg, "True clumps found "
- "(HDU: `%s').", demo->name);
+ if( asprintf(&msg, "True clumps found "
+ "(HDU: `%s').", demo->name)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation",
+ __func__);
gal_timing_report(NULL, msg, 2);
free(msg);
}
@@ -712,8 +717,10 @@ segmentation_detections(struct noisechiselparams *p)
if(!p->cp.quiet)
{
gal_timing_report(NULL, "Starting to identify objects.", 1);
- asprintf(&msg, "True clumps grown "
- "(HDU: `%s').", demo->name);
+ if( asprintf(&msg, "True clumps grown "
+ "(HDU: `%s').", demo->name)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation",
+ __func__);
gal_timing_report(NULL, msg, 2);
free(msg);
}
@@ -724,8 +731,10 @@ segmentation_detections(struct noisechiselparams *p)
demo->name = "DET_OBJ_IDENTIFIED";
if(!p->cp.quiet)
{
- asprintf(&msg, "Identified objects over detections "
- "(HDU: `%s').", demo->name);
+ if( asprintf(&msg, "Identified objects over detections "
+ "(HDU: `%s').", demo->name)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation",
+ __func__);
gal_timing_report(NULL, msg, 2);
free(msg);
}
@@ -736,8 +745,10 @@ segmentation_detections(struct noisechiselparams *p)
demo->name = "DET_OBJECTS_FULL";
if(!p->cp.quiet)
{
- asprintf(&msg, "Objects grown to cover full area "
- "(HDU: `%s').", demo->name);
+ if( asprintf(&msg, "Objects grown to cover full area "
+ "(HDU: `%s').", demo->name)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation",
+ __func__);
gal_timing_report(NULL, msg, 2);
free(msg);
}
@@ -748,8 +759,10 @@ segmentation_detections(struct noisechiselparams *p)
demo->name = "CLUMPS_FINAL";
if(!p->cp.quiet)
{
- asprintf(&msg, "Clumps given their final label "
- "(HDU: `%s').", demo->name);
+ if( asprintf(&msg, "Clumps given their final label "
+ "(HDU: `%s').", demo->name)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation",
+ __func__);
gal_timing_report(NULL, msg, 2);
free(msg);
}
@@ -760,8 +773,10 @@ segmentation_detections(struct noisechiselparams *p)
demo->name = "OBJECTS_FINAL";
if(!p->cp.quiet)
{
- asprintf(&msg, "Objects given their final label "
- "(HDU: `%s').", demo->name);
+ if( asprintf(&msg, "Objects given their final label "
+ "(HDU: `%s').", demo->name)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation",
+ __func__);
gal_timing_report(NULL, msg, 2);
free(msg);
}
@@ -896,9 +911,10 @@ segmentation(struct noisechiselparams *p)
/* Report the results and timing to the user. */
if(!p->cp.quiet)
{
- asprintf(&msg, "%zu object%s""containing %zu clump%sfound.",
- p->numobjects, p->numobjects==1 ? " " : "s ",
- p->numclumps, p->numclumps ==1 ? " " : "s ");
+ if( asprintf(&msg, "%zu object%s""containing %zu clump%sfound.",
+ p->numobjects, p->numobjects==1 ? " " : "s ",
+ p->numclumps, p->numclumps ==1 ? " " : "s ")<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(&t1, msg, 1);
free(msg);
}
diff --git a/bin/noisechisel/threshold.c b/bin/noisechisel/threshold.c
index f173b97..565e9ac 100644
--- a/bin/noisechisel/threshold.c
+++ b/bin/noisechisel/threshold.c
@@ -759,8 +759,9 @@ threshold_quantile_find_apply(struct noisechiselparams *p)
gal_data_free(qprm.noerode_th);
if(!p->cp.quiet)
{
- asprintf(&msg, "%.2f & %0.2f quantile thresholds applied.",
- p->qthresh, p->noerodequant);
+ if( asprintf(&msg, "%.2f & %0.2f quantile thresholds applied.",
+ p->qthresh, p->noerodequant)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(&t1, msg, 2);
free(msg);
}
diff --git a/bin/noisechisel/ui.c b/bin/noisechisel/ui.c
index 267336a..bb3ee92 100644
--- a/bin/noisechisel/ui.c
+++ b/bin/noisechisel/ui.c
@@ -761,8 +761,16 @@ ui_abort_after_check(struct noisechiselparams *p, char
*filename,
{
char *name;
- if(file2name) asprintf(&name, "`%s' and `%s'", filename, file2name);
- else asprintf(&name, "`%s'", filename);
+ if(file2name)
+ {
+ if( asprintf(&name, "`%s' and `%s'", filename, file2name)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&name, "`%s'", filename)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
/* Let the user know that NoiseChisel is aborting. */
fprintf(stderr,
diff --git a/bin/statistics/sky.c b/bin/statistics/sky.c
index dfa0b27..a77d70a 100644
--- a/bin/statistics/sky.c
+++ b/bin/statistics/sky.c
@@ -184,8 +184,9 @@ sky(struct statisticsparams *p)
if(!cp->quiet)
{
num=gal_statistics_number(p->sky_t);
- asprintf(&msg, "Sky and its STD found on %zu/%zu tiles.",
- (size_t)(*((uint64_t *)(num->array))), tl->tottiles );
+ if( asprintf(&msg, "Sky and its STD found on %zu/%zu tiles.",
+ (size_t)(*((uint64_t *)(num->array))), tl->tottiles )<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(&t1, msg, 1);
gal_data_free(num);
free(msg);
diff --git a/bin/statistics/statistics.c b/bin/statistics/statistics.c
index 481e896..42a80dc 100644
--- a/bin/statistics/statistics.c
+++ b/bin/statistics/statistics.c
@@ -538,7 +538,8 @@ write_output_table(struct statisticsparams *p, gal_data_t
*table,
? gal_fits_name_is_fits(p->cp.output) ? "fits" : "txt"
: "txt" );
if(use_auto_output)
- asprintf(&suffix, "%s.%s", suf, fix);
+ if( asprintf(&suffix, "%s.%s", suf, fix)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
/* Make the output name. */
@@ -553,7 +554,8 @@ write_output_table(struct statisticsparams *p, gal_data_t
*table,
tmp=gal_fits_name_save_as_string(p->inputname, p->cp.hdu);
gal_list_str_add(&comments, tmp, 0);
- asprintf(&tmp, "%s created from:", contents);
+ if( asprintf(&tmp, "%s created from:", contents)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_list_str_add(&comments, tmp, 0);
if(strcmp(fix, "fits")) /* The intro info will be in FITS files anyway.*/
@@ -720,12 +722,21 @@ print_input_info(struct statisticsparams *p)
/* Range. */
str=NULL;
if( !isnan(p->greaterequal) && !isnan(p->lessthan) )
- asprintf(&str, "from (inclusive) %g, up to (exclusive) %g",
- p->greaterequal, p->lessthan);
+ {
+ if( asprintf(&str, "from (inclusive) %g, up to (exclusive) %g",
+ p->greaterequal, p->lessthan)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
else if( !isnan(p->greaterequal) )
- asprintf(&str, "from (inclusive) %g", p->greaterequal);
+ {
+ if( asprintf(&str, "from (inclusive) %g", p->greaterequal)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
else if( !isnan(p->lessthan) )
- asprintf(&str, "up to (exclusive) %g", p->lessthan);
+ {
+ if( asprintf(&str, "up to (exclusive) %g", p->lessthan)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
if(str)
{
printf("Range: ");
@@ -861,10 +872,16 @@ print_sigma_clip(struct statisticsparams *p)
/* Set the mode for printing: */
if( p->sclipparams[1]>=1.0f )
- asprintf(&mode, "for %g clips", p->sclipparams[1]);
+ {
+ if( asprintf(&mode, "for %g clips", p->sclipparams[1])<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
else
- asprintf(&mode, "until relative change in STD is less than %g",
- p->sclipparams[1]);
+ {
+ if( asprintf(&mode, "until relative change in STD is less than %g",
+ p->sclipparams[1])<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
/* Report the status */
if(!p->cp.quiet)
diff --git a/bin/statistics/ui.c b/bin/statistics/ui.c
index b349633..4c4b652 100644
--- a/bin/statistics/ui.c
+++ b/bin/statistics/ui.c
@@ -296,8 +296,16 @@ ui_read_quantile_range(struct argp_option *option, char
*arg,
/* For the `--printparams' (`-P') option:*/
if(lineno==-1)
{
- if( isnan(p->quantmax) ) asprintf(&str, "%g", p->quantmin);
- else asprintf(&str, "%g,%g", p->quantmin, p->quantmax);
+ if( isnan(p->quantmax) )
+ {
+ if( asprintf(&str, "%g", p->quantmin)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&str, "%g,%g", p->quantmin, p->quantmax)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
return str;
}
@@ -524,7 +532,8 @@ ui_check_options_and_arguments(struct statisticsparams *p)
"to tables.", p->inputname, p->cp.hdu);
}
else if(p->column==NULL)
- asprintf(&name, "%s (hdu: %s)", p->inputname, p->cp.hdu);
+ if( asprintf(&name, "%s (hdu: %s)", p->inputname, p->cp.hdu)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
}
/* If its not FITS, it must be a table. */
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index 8daf72e..a0d9bf5 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -3,3 +3,4 @@ People who's help must be acknowledged in the next release.
Antonio Diaz Diaz
Guillaume Mahler
Ole Streicher
+Éric Thiébaut
diff --git a/lib/blank.c b/lib/blank.c
index 154d1ca..98b69f3 100644
--- a/lib/blank.c
+++ b/lib/blank.c
@@ -385,66 +385,154 @@ gal_blank_as_string(uint8_t type, int width)
break;
case GAL_TYPE_STRING:
- if(width) asprintf(&blank, "%*s", width, GAL_BLANK_STRING);
- else asprintf(&blank, "%s", GAL_BLANK_STRING);
+ if(width)
+ {
+ if( asprintf(&blank, "%*s", width, GAL_BLANK_STRING)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&blank, "%s", GAL_BLANK_STRING)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
break;
case GAL_TYPE_UINT8:
fmt = width ? "%*"PRIu8 : "%"PRIu8;
- if(width) asprintf(&blank, fmt, width, (uint8_t)GAL_BLANK_UINT8);
- else asprintf(&blank, fmt, (uint8_t)GAL_BLANK_UINT8);
+ if(width)
+ {
+ if( asprintf(&blank, fmt, width, (uint8_t)GAL_BLANK_UINT8)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&blank, fmt, (uint8_t)GAL_BLANK_UINT8)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
break;
case GAL_TYPE_INT8:
fmt = width ? "%*"PRId8 : "%"PRId8;
- if(width) asprintf(&blank, fmt, width, (int8_t)GAL_BLANK_INT8);
- else asprintf(&blank, fmt, (int8_t)GAL_BLANK_INT8);
+ if(width)
+ {
+ if( asprintf(&blank, fmt, width, (int8_t)GAL_BLANK_INT8)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&blank, fmt, (int8_t)GAL_BLANK_INT8)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
break;
case GAL_TYPE_UINT16:
fmt = width ? "%*"PRIu16 : "%"PRIu16;
- if(width) asprintf(&blank, fmt, width, (uint16_t)GAL_BLANK_UINT16);
- else asprintf(&blank, fmt, (uint16_t)GAL_BLANK_UINT16);
+ if(width)
+ {
+ if( asprintf(&blank, fmt, width, (uint16_t)GAL_BLANK_UINT16)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&blank, fmt, (uint16_t)GAL_BLANK_UINT16)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
break;
case GAL_TYPE_INT16:
fmt = width ? "%*"PRId16 : "%"PRId16;
- if(width) asprintf(&blank, fmt, width, (int16_t)GAL_BLANK_INT16);
- else asprintf(&blank, fmt, (int16_t)GAL_BLANK_INT16);
+ if(width)
+ {
+ if( asprintf(&blank, fmt, width, (int16_t)GAL_BLANK_INT16)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&blank, fmt, (int16_t)GAL_BLANK_INT16)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
break;
case GAL_TYPE_UINT32:
fmt = width ? "%*"PRIu32 : "%"PRIu32;
- if(width) asprintf(&blank, fmt, width, (uint32_t)GAL_BLANK_UINT32);
- else asprintf(&blank, fmt, (uint32_t)GAL_BLANK_UINT32);
+ if(width)
+ {
+ if( asprintf(&blank, fmt, width, (uint32_t)GAL_BLANK_UINT32)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&blank, fmt, (uint32_t)GAL_BLANK_UINT32)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
break;
case GAL_TYPE_INT32:
fmt = width ? "%*"PRId32 : "%"PRId32;
- if(width) asprintf(&blank, fmt, width, (int32_t)GAL_BLANK_INT32);
- else asprintf(&blank, fmt, (int32_t)GAL_BLANK_INT32);
+ if(width)
+ {
+ if( asprintf(&blank, fmt, width, (int32_t)GAL_BLANK_INT32)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&blank, fmt, (int32_t)GAL_BLANK_INT32)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
break;
case GAL_TYPE_UINT64:
fmt = width ? "%*"PRIu64 : "%"PRIu64;
- if(width) asprintf(&blank, fmt, width, (uint64_t)GAL_BLANK_UINT64);
- else asprintf(&blank, fmt, (uint64_t)GAL_BLANK_UINT64);
+ if(width)
+ {
+ if( asprintf(&blank, fmt, width, (uint64_t)GAL_BLANK_UINT64)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&blank, fmt, (uint64_t)GAL_BLANK_UINT64)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
break;
case GAL_TYPE_INT64:
fmt = width ? "%*"PRId64 : "%"PRId64;
- if(width) asprintf(&blank, fmt, width, (int64_t)GAL_BLANK_INT64);
- else asprintf(&blank, fmt, (int64_t)GAL_BLANK_INT64);
+ if(width)
+ {
+ if( asprintf(&blank, fmt, width, (int64_t)GAL_BLANK_INT64)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&blank, fmt, (int64_t)GAL_BLANK_INT64)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
break;
case GAL_TYPE_FLOAT32:
- if(width) asprintf(&blank, "%*f", width, (float)GAL_BLANK_FLOAT32);
- else asprintf(&blank, "%f", (float)GAL_BLANK_FLOAT32);
+ if(width)
+ {
+ if( asprintf(&blank, "%*f", width, (float)GAL_BLANK_FLOAT32)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&blank, "%f", (float)GAL_BLANK_FLOAT32)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
break;
case GAL_TYPE_FLOAT64:
- if(width) asprintf(&blank, "%*f", width, (double)GAL_BLANK_FLOAT64);
- else asprintf(&blank, "%f", (double)GAL_BLANK_FLOAT64);
+ if(width)
+ {
+ if( asprintf(&blank, "%*f", width, (double)GAL_BLANK_FLOAT64)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&blank, "%f", (double)GAL_BLANK_FLOAT64)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
break;
default:
diff --git a/lib/checkset.c b/lib/checkset.c
index bbb1541..af5d01c 100644
--- a/lib/checkset.c
+++ b/lib/checkset.c
@@ -146,7 +146,10 @@ gal_checkset_dataset_name(char *filename, char *hdu)
{
char *out;
if( gal_fits_name_is_fits(filename) )
- asprintf(&out, "%s (hdu %s)", filename, hdu);
+ {
+ if( asprintf(&out, "%s (hdu %s)", filename, hdu)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
else
gal_checkset_allocate_copy(filename, &out);
return out;
diff --git a/lib/data.c b/lib/data.c
index 29920c2..d3e85e1 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -678,7 +678,11 @@ data_copy_from_string(gal_data_t *from, gal_data_t *to)
CTYPE *a=from->array; \
for(i=0;i<from->size;++i) \
{ \
- if(a[i]!=BLANK) asprintf(&strarr[i], FMT, a[i]); \
+ if(a[i]!=BLANK) \
+ { \
+ if( asprintf(&strarr[i], FMT, a[i])<0 ) \
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__); \
+ } \
else \
gal_checkset_allocate_copy(GAL_BLANK_STRING, &strarr[i]); \
} \
@@ -690,7 +694,11 @@ data_copy_from_string(gal_data_t *from, gal_data_t *to)
{ \
if(isnan(BLANK)) isblank = isnan(a[i]) ? 1 : 0; \
else isblank = a[i]==BLANK ? 1 : 0; \
- if(isblank==0) asprintf(&strarr[i], "%f", a[i]); \
+ if(isblank==0) \
+ { \
+ if( asprintf(&strarr[i], "%f", a[i])<0 ) \
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__); \
+ } \
else gal_checkset_allocate_copy(GAL_BLANK_STRING, &strarr[i]); \
} \
}
diff --git a/lib/fits.c b/lib/fits.c
index 7c9efa4..939d816 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -147,7 +147,10 @@ gal_fits_name_save_as_string(char *filename, char *hdu)
{
char *name;
if( gal_fits_name_is_fits(filename) )
- asprintf(&name, "%s (hdu: %s)", filename, hdu);
+ {
+ if( asprintf(&name, "%s (hdu: %s)", filename, hdu)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
else gal_checkset_allocate_copy(filename, &name);
return name;
}
@@ -671,7 +674,8 @@ gal_fits_hdu_open(char *filename, char *hdu, int iomode)
fitsfile *fptr;
/* Add hdu to filename: */
- asprintf(&ffname, "%s[%s#]", filename, hdu);
+ if( asprintf(&ffname, "%s[%s#]", filename, hdu)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
/* Open the FITS file: */
if( fits_open_file(&fptr, ffname, iomode, &status) )
@@ -2494,8 +2498,10 @@ fits_table_prepare_arrays(gal_data_t *cols, size_t
numcols, int tableformat,
for(col=cols; col!=NULL; col=col->next)
{
/* Set the `ttype' and `tunit' values: */
- asprintf(&ttype[i], "%s", col->name ? col->name : "");
- asprintf(&tunit[i], "%s", col->unit ? col->unit : "");
+ if( asprintf(&ttype[i], "%s", col->name ? col->name : "")<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ if( asprintf(&tunit[i], "%s", col->unit ? col->unit : "")<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
/* FITS's TFORM depends on the type of FITS table, so work
@@ -2537,13 +2543,15 @@ fits_table_prepare_arrays(gal_data_t *cols, size_t
numcols, int tableformat,
case GAL_TYPE_INT32:
case GAL_TYPE_UINT64:
case GAL_TYPE_INT64:
- asprintf(&tform[i], "%c%d", fmt[0], col->disp_width);
+ if( asprintf(&tform[i], "%c%d", fmt[0], col->disp_width)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
break;
case GAL_TYPE_FLOAT32:
case GAL_TYPE_FLOAT64:
- asprintf(&tform[i], "%c%d.%d", fmt[0], col->disp_width,
- col->disp_precision);
+ if( asprintf(&tform[i], "%c%d.%d", fmt[0], col->disp_width,
+ col->disp_precision)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
break;
default:
@@ -2561,9 +2569,15 @@ fits_table_prepare_arrays(gal_data_t *cols, size_t
numcols, int tableformat,
col->disp_width=fits_string_fixed_alloc_size(col);
fmt[0]=gal_fits_type_to_bin_tform(col->type);
if( col->type==GAL_TYPE_STRING )
- asprintf(&tform[i], "%d%c", col->disp_width, fmt[0]);
+ {
+ if( asprintf(&tform[i], "%d%c", col->disp_width, fmt[0])<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
else
- asprintf(&tform[i], "%c", fmt[0]);
+ {
+ if( asprintf(&tform[i], "%c", fmt[0])<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
break;
default:
@@ -2599,7 +2613,8 @@ fits_write_tnull_tcomm(fitsfile *fptr, gal_data_t *col,
int tableformat,
case GAL_TABLE_FORMAT_AFITS:
/* Print the keyword and value. */
- asprintf(&keyname, "TNULL%zu", colnum);
+ if( asprintf(&keyname, "TNULL%zu", colnum)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
blank=gal_blank_as_string(col->type, col->disp_width);
/* When in exponential form (`tform' starting with `E'), CFITSIO
@@ -2627,7 +2642,8 @@ fits_write_tnull_tcomm(fitsfile *fptr, gal_data_t *col,
int tableformat,
&& col->type!=GAL_TYPE_STRING )
{
blank=gal_blank_alloc_write(col->type);
- asprintf(&keyname, "TNULL%zu", colnum);
+ if( asprintf(&keyname, "TNULL%zu", colnum)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
fits_write_key(fptr, gal_fits_type_to_datatype(col->type),
keyname, blank, "blank value for this column",
&status);
@@ -2645,8 +2661,10 @@ fits_write_tnull_tcomm(fitsfile *fptr, gal_data_t *col,
int tableformat,
/* Write the comments if there is any. */
if(col->comment)
{
- asprintf(&keyname, "TCOMM%zu", colnum);
- asprintf(&bcomment, "comment for field %zu", colnum);
+ if( asprintf(&keyname, "TCOMM%zu", colnum)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ if( asprintf(&bcomment, "comment for field %zu", colnum)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
fits_write_key(fptr, TSTRING, keyname, col->comment,
bcomment, &status);
gal_fits_io_error(status, NULL);
diff --git a/lib/options.c b/lib/options.c
index fea6a6f..75c9423 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -266,15 +266,16 @@ gal_options_print_citation(struct argp_option *option,
char *arg,
/* Notice for acknowledgements. */
- asprintf(&gnuastro_acknowledgement,
- "Acknowledgement\n"
- "---------------\n"
- "This work was partly done using GNU Astronomy Utilities "
- "(Gnuastro) version %s. Gnuastro is a generic package for "
- "astronomical data manipulation and analysis which was "
- "initially created and developed for research funded by the "
- "Monbukagakusho (Japanese government) scholarship and ERC "
- "advanced grant 339659-MUSICOS.", PACKAGE_VERSION);
+ if( asprintf(&gnuastro_acknowledgement,
+ "Acknowledgement\n"
+ "---------------\n"
+ "This work was partly done using GNU Astronomy Utilities "
+ "(Gnuastro) version %s. Gnuastro is a generic package for "
+ "astronomical data manipulation and analysis which was "
+ "initially created and developed for research funded by the "
+ "Monbukagakusho (Japanese government) scholarship and ERC "
+ "advanced grant 339659-MUSICOS.", PACKAGE_VERSION)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
printf("%s\n", gnuastro_acknowledgement);
free(gnuastro_acknowledgement);
@@ -877,7 +878,8 @@ gal_options_read_sigma_clip(struct argp_option *option,
char *arg,
/* Caller wants to print the option values. */
if(lineno==-1)
{
- asprintf(&str, "%g,%g", sigmaclip[0], sigmaclip[1]);
+ if( asprintf(&str, "%g,%g", sigmaclip[0], sigmaclip[1])<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
return str;
}
@@ -1623,12 +1625,14 @@ gal_options_parse_config_files(struct
gal_options_common_params *cp)
"`uint8' type", __func__, PACKAGE_BUGREPORT);
/* The program's current directory configuration file. */
- asprintf(&filename, ".%s/%s.conf", PACKAGE, cp->program_exec);
+ if( asprintf(&filename, ".%s/%s.conf", PACKAGE, cp->program_exec)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
options_parse_file(filename, cp, 0);
free(filename);
/* Common options configuration file. */
- asprintf(&filename, ".%s/%s.conf", PACKAGE, PACKAGE);
+ if( asprintf(&filename, ".%s/%s.conf", PACKAGE, PACKAGE)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
options_parse_file(filename, cp, 0);
free(filename);
@@ -1636,23 +1640,27 @@ gal_options_parse_config_files(struct
gal_options_common_params *cp)
home=options_get_home();
/* The program's user-wide configuration file. */
- asprintf(&filename, "%s/%s/%s.conf", home, USERCONFIG_DIR,
- cp->program_exec);
+ if( asprintf(&filename, "%s/%s/%s.conf", home, USERCONFIG_DIR,
+ cp->program_exec)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
options_parse_file(filename, cp, 0);
free(filename);
/* Common options user-wide configuration file. */
- asprintf(&filename, "%s/%s/%s.conf", home, USERCONFIG_DIR, PACKAGE);
+ if( asprintf(&filename, "%s/%s/%s.conf", home, USERCONFIG_DIR, PACKAGE)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
options_parse_file(filename, cp, 0);
free(filename);
/* The program's system-wide configuration file. */
- asprintf(&filename, "%s/%s.conf", SYSCONFIG_DIR, cp->program_exec);
+ if( asprintf(&filename, "%s/%s.conf", SYSCONFIG_DIR, cp->program_exec)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
options_parse_file(filename, cp, 0);
free(filename);
/* Common options system-wide configuration file. */
- asprintf(&filename, "%s/%s.conf", SYSCONFIG_DIR, PACKAGE);
+ if( asprintf(&filename, "%s/%s.conf", SYSCONFIG_DIR, PACKAGE)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
options_parse_file(filename, cp, 0);
free(filename);
}
@@ -1991,7 +1999,8 @@ options_print_all(struct gal_options_common_params *cp,
char *dirname,
gal_checkset_mkdir(dirname);
/* Prepare the full filename: */
- asprintf(&filename, "%s/%s.conf", dirname, cp->program_exec);
+ if( asprintf(&filename, "%s/%s.conf", dirname, cp->program_exec)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
/* Remove the file if it already exists. */
gal_checkset_writable_remove(filename, 0, 0);
@@ -2128,14 +2137,16 @@ gal_options_print_state(struct
gal_options_common_params *cp)
break;
case GAL_OPTIONS_KEY_SETDIRCONF:
- asprintf(&dirname, ".%s", PACKAGE);
+ if( asprintf(&dirname, ".%s", PACKAGE)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
options_print_all(cp, dirname, cp->coptions[i].name);
free(dirname);
break;
case GAL_OPTIONS_KEY_SETUSRCONF:
home=options_get_home();
- asprintf(&dirname, "%s/%s", home, USERCONFIG_DIR);
+ if( asprintf(&dirname, "%s/%s", home, USERCONFIG_DIR)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
options_print_all(cp, dirname, cp->coptions[i].name);
free(dirname);
break;
diff --git a/lib/table.c b/lib/table.c
index e74eaee..a263700 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -358,8 +358,10 @@ make_list_of_indexs(gal_list_str_t *cols, gal_data_t
*allcols,
are done (and program is aborted) before this step. */
if(nummatch==0)
{
- asprintf(&errorstring, "`%s' didn't match any of the column %ss.",
- tmp->v, gal_tableintern_searchin_as_string(searchin));
+ if( asprintf(&errorstring, "`%s' didn't match any of the "
+ "column %ss.", tmp->v,
+ gal_tableintern_searchin_as_string(searchin))<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_tableintern_error_col_selection(filename, hdu, errorstring);
}
@@ -500,7 +502,8 @@ gal_table_comments_add_intro(gal_list_str_t **comments,
char *program_string,
line. Note that ctime puts a `\n' at the end of its string, so we'll
have to remove that. Also, note that since we are allocating `msg', we
are setting the allocate flag of `gal_list_str_add' to 0. */
- asprintf(&tmp, "Created%s on %s", gitdescribe, ctime(rawtime));
+ if( asprintf(&tmp, "Created%s on %s", gitdescribe, ctime(rawtime))<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
tmp[ strlen(tmp)-1 ]='\0';
gal_list_str_add(comments, tmp, 0);
@@ -558,7 +561,8 @@ gal_table_write_log(gal_data_t *logll, char *program_string,
/* In verbose mode, print the information. */
if(!quiet)
{
- asprintf(&msg, "%s created.", filename);
+ if( asprintf(&msg, "%s created.", filename)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
gal_timing_report(NULL, msg, 1);
free(msg);
}
diff --git a/lib/tableintern.c b/lib/tableintern.c
index bae354a..b6e0bdb 100644
--- a/lib/tableintern.c
+++ b/lib/tableintern.c
@@ -54,10 +54,12 @@ gal_tableintern_error_col_selection(char *filename, char
*hdu,
/* Set the proper pointers. */
if(gal_fits_name_is_fits(filename))
{
- asprintf(&name, "%s (hdu: %s)", filename, hdu);
+ if( asprintf(&name, "%s (hdu: %s)", filename, hdu)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
c=hdu; while(*c!='\0') if(isspace(*c++)) break;
- asprintf(&command, *c=='\0' ? "%s --hdu=%s" : "%s --hdu=\"%s\"",
- filename, hdu);
+ if( asprintf(&command, *c=='\0' ? "%s --hdu=%s" : "%s --hdu=\"%s\"",
+ filename, hdu)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
}
else command=name=filename;
diff --git a/lib/txt.c b/lib/txt.c
index a2272dd..f329232 100644
--- a/lib/txt.c
+++ b/lib/txt.c
@@ -1206,7 +1206,8 @@ txt_open_file_write_info(gal_data_t *datall, char **fmts,
over-write the one that `sprintf' puts with a `:' for the columns
that have the same number of digits as the final column. */
i=0;
- asprintf(&nstr, "%zu:", num);
+ if( asprintf(&nstr, "%zu:", num)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
nlen=strlen(nstr);
for(data=datall; data!=NULL; data=data->next)
{
diff --git a/lib/type.c b/lib/type.c
index de61f56..f59981d 100644
--- a/lib/type.c
+++ b/lib/type.c
@@ -362,7 +362,10 @@ gal_type_bit_string(void *in, size_t size)
/* Write the contents of memory that `ptr' points to as a string of type
`type'.*/
-#define TO_STRING(CTYPE, FMT) asprintf(&str, FMT, *(CTYPE *)ptr);
+#define TO_STRING(CTYPE, FMT) { \
+ if( asprintf(&str, FMT, *(CTYPE *)ptr)<0 ) \
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__); }
+
char *
gal_type_to_string(void *ptr, uint8_t type, int quote_if_str_has_space)
{
@@ -376,11 +379,20 @@ gal_type_to_string(void *ptr, uint8_t type, int
quote_if_str_has_space)
if(quote_if_str_has_space)
{
c=*(char **)ptr; while(*c!='\0') if(isspace(*c++)) break;
- if(*c=='\0') asprintf(&str, "%s", *(char **)ptr);
- else asprintf(&str, "\"%s\" ", *(char **)ptr);
+ if(*c=='\0')
+ {
+ if( asprintf(&str, "%s", *(char **)ptr)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&str, "\"%s\" ", *(char **)ptr)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
}
else
- asprintf(&str, "%s", *(char **)ptr);
+ if( asprintf(&str, "%s", *(char **)ptr)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
break;
case GAL_TYPE_UINT8: TO_STRING( uint8_t, "%"PRIu8 ); break;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master d6b4d9c: Return value of asprintf now checked,
Mohammad Akhlaghi <=