From f89c3328fd291a3854859c9634195582d098f520 Mon Sep 17 00:00:00 2001 From: Balint Reczey Date: Tue, 13 Feb 2018 00:44:27 +0700 Subject: [PATCH 1/2] Fix interp2d info Fixes interp2d_test. --- ext/gsl_native/interp2d.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/ext/gsl_native/interp2d.c b/ext/gsl_native/interp2d.c index e086eab6..1e9b76a3 100644 --- a/ext/gsl_native/interp2d.c +++ b/ext/gsl_native/interp2d.c @@ -235,15 +235,26 @@ static VALUE rb_gsl_interp2d_info(VALUE self) rb_gsl_interp2d *p; char buf[256]; Data_Get_Struct(self, rb_gsl_interp2d, p); - sprintf(buf, "Class: %s\n", rb_class2name(CLASS_OF(self))); - sprintf(buf, "%sSuperClass: %s\n", buf, rb_class2name(RCLASS_SUPER(CLASS_OF(self)))); - sprintf(buf, "%sType: %s\n", buf, gsl_interp2d_name(p->p)); - sprintf(buf, "%sxmin: %f\n", buf, p->p->xmin); - sprintf(buf, "%sxmax: %f\n", buf, p->p->xmax); - sprintf(buf, "%symin: %f\n", buf, p->p->ymin); - sprintf(buf, "%symax: %f\n", buf, p->p->ymax); - sprintf(buf, "%sxsize: %d\n", buf, (int) p->p->xsize); - sprintf(buf, "%sysize: %d\n", buf, (int) p->p->ysize); + snprintf(buf, sizeof(buf)-1, + "Class: %s\n" + "SuperClass: %s\n" + "Type: %s\n" + "xmin: %f\n" + "xmax: %f\n" + "ymin: %f\n" + "ymax: %f\n" + "xsize: %d\n" + "ysize: %d\n", + rb_class2name(CLASS_OF(self)), + rb_class2name(RCLASS_SUPER(CLASS_OF(self))), + gsl_interp2d_name(p->p), + p->p->xmin, + p->p->xmax, + p->p->ymin, + p->p->ymax, + (int) p->p->xsize, + (int) p->p->ysize); + buf[sizeof(buf) - 1] = '\0'; return rb_str_new2(buf); } From 6b7c74e063269d3ec9e0e0628eb66226468f3fa8 Mon Sep 17 00:00:00 2001 From: Balint Reczey Date: Tue, 13 Feb 2018 01:28:49 +0700 Subject: [PATCH 2/2] Fix spline2d info Fixes spline2d_test. --- ext/gsl_native/spline2d.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/ext/gsl_native/spline2d.c b/ext/gsl_native/spline2d.c index 34e0c2bd..5b9c2627 100644 --- a/ext/gsl_native/spline2d.c +++ b/ext/gsl_native/spline2d.c @@ -180,15 +180,27 @@ static VALUE rb_gsl_spline2d_info(VALUE self) rb_gsl_spline2d *p = NULL; char buf[256]; Data_Get_Struct(self, rb_gsl_spline2d, p); - sprintf(buf, "Class: %s\n", rb_class2name(CLASS_OF(self))); - sprintf(buf, "%sSuperClass: %s\n", buf, rb_class2name(RCLASS_SUPER(CLASS_OF(self)))); - sprintf(buf, "%sType: %s\n", buf, gsl_interp2d_name(&p->s->interp_object)); - sprintf(buf, "%sxmin: %f\n", buf, p->s->interp_object.xmin); - sprintf(buf, "%sxmax: %f\n", buf, p->s->interp_object.xmax); - sprintf(buf, "%symin: %f\n", buf, p->s->interp_object.ymin); - sprintf(buf, "%symax: %f\n", buf, p->s->interp_object.ymax); - sprintf(buf, "%sxSize: %d\n", buf, (int) p->s->interp_object.xsize); - sprintf(buf, "%sySize: %d\n", buf, (int) p->s->interp_object.ysize); + snprintf(buf, sizeof(buf) - 1, + "Class: %s\n" + "SuperClass: %s\n" + "Type: %s\n" + "xmin: %f\n" + "xmax: %f\n" + "ymin: %f\n" + "ymax: %f\n" + "xSize: %d\n" + "ySize: %d\n", + rb_class2name(CLASS_OF(self)), + rb_class2name(RCLASS_SUPER(CLASS_OF(self))), + gsl_interp2d_name(&p->s->interp_object), + p->s->interp_object.xmin, + p->s->interp_object.xmax, + p->s->interp_object.ymin, + p->s->interp_object.ymax, + (int) p->s->interp_object.xsize, + (int) p->s->interp_object.ysize); + buf[sizeof(buf) - 1] = '\0'; + return rb_str_new2(buf); }