diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index e976e0f..3a916d5 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -1123,7 +1123,7 @@ Context2d::GetShadowColor(Local prop, const AccessorInfo &info) { HandleScope scope; char buf[64]; Context2d *context = ObjectWrap::Unwrap(info.This()); - rgba_to_string(context->state->shadow, buf); + rgba_to_string(context->state->shadow, buf, sizeof(buf)); return scope.Close(String::New(buf)); } @@ -1154,7 +1154,7 @@ Context2d::GetFillColor(Local prop, const AccessorInfo &info) { HandleScope scope; char buf[64]; Context2d *context = ObjectWrap::Unwrap(info.This()); - rgba_to_string(context->state->fill, buf); + rgba_to_string(context->state->fill, buf, sizeof(buf)); return scope.Close(String::New(buf)); } @@ -1185,7 +1185,7 @@ Context2d::GetStrokeColor(Local prop, const AccessorInfo &info) { HandleScope scope; char buf[64]; Context2d *context = ObjectWrap::Unwrap(info.This()); - rgba_to_string(context->state->stroke, buf); + rgba_to_string(context->state->stroke, buf, sizeof(buf)); return scope.Close(String::New(buf)); } diff --git a/src/color.cc b/src/color.cc index bb768d5..a3440c3 100644 --- a/src/color.cc +++ b/src/color.cc @@ -243,14 +243,14 @@ rgba_create(uint32_t rgba) { */ void -rgba_to_string(rgba_t rgba, char *buf) { +rgba_to_string(rgba_t rgba, char *buf, size_t buf_size) { if (1 == rgba.a) { - sprintf(buf, "#%.2x%.2x%.2x" + snprintf(buf, buf_size, "#%.2x%.2x%.2x" , (int) (rgba.r * 255) , (int) (rgba.g * 255) , (int) (rgba.b * 255)); } else { - sprintf(buf, "rgba(%d, %d, %d, %.2f)" + snprintf(buf, buf_size, "rgba(%d, %d, %d, %.2f)" , (int) (rgba.r * 255) , (int) (rgba.g * 255) , (int) (rgba.b * 255) diff --git a/src/color.h b/src/color.h index 10de606..9d0a351 100644 --- a/src/color.h +++ b/src/color.h @@ -11,6 +11,7 @@ #include #include #include +#include /* * RGBA struct. @@ -31,7 +32,7 @@ int32_t rgba_from_string(const char *str, short *ok); void -rgba_to_string(rgba_t rgba, char *buf); +rgba_to_string(rgba_t rgba, char *buf, size_t buf_size); void rgba_inspect(int32_t rgba);