changeset 2013:862a943afff4

Fix some warnings in regards to strncpy().
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 06 Aug 2018 15:25:12 +0300
parents bec158e00f17
children a49f7e83edcb
files src/dmengine.h src/dmtimelinew.c
diffstat 2 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/dmengine.h	Mon Jul 23 15:15:37 2018 +0300
+++ b/src/dmengine.h	Mon Aug 06 15:25:12 2018 +0300
@@ -340,7 +340,7 @@
 int  dmCopyTimelineTrack(const DMTimelineTrack *src, DMTimelineTrack **pdst);
 int  dmCopyTimeline(const DMTimeline *src, DMTimeline **pdst);
 
-int  dmSaveTimeline(DMResource *res, DMTimeline *tl);
+int  dmSaveTimeline(DMResource *res, const DMTimeline *tl);
 
 int  dmTimelineNew(DMTimeline **tl, const char *name);
 int  dmTimelineAddTrack(DMTimeline *tl, DMTimelineTrack **track, const char *name);
--- a/src/dmtimelinew.c	Mon Jul 23 15:15:37 2018 +0300
+++ b/src/dmtimelinew.c	Mon Aug 06 15:25:12 2018 +0300
@@ -7,7 +7,7 @@
 #include "dmengine.h"
 
 
-static BOOL dmSaveFloatValue(DMResource *res, DMFloat val)
+static BOOL dmSaveFloatValue(DMResource *res, const DMFloat val)
 {
     char tmp[DT_FLOAT_STORE_SIZE];
     snprintf(tmp, DT_FLOAT_STORE_SIZE, "%f", val);
@@ -15,7 +15,7 @@
 }
 
 
-static int dmSaveTimelinePoints(DMResource *res, DMTimelinePoints *points, int type)
+static int dmSaveTimelinePoints(DMResource *res, const DMTimelinePoints *points, const int type)
 {
     int point;
     Uint32 npoints;
@@ -73,7 +73,7 @@
 }
 
 
-static int dmSaveTimelineCurve(DMResource *res, DMTimelineCurve *curve)
+static int dmSaveTimelineCurve(DMResource *res, const DMTimelineCurve *curve)
 {
     int err;
 
@@ -87,13 +87,14 @@
 }
 
 
-static int dmSaveTimelineEventParam(DMResource *res, DMTimelineEventParam *param)
+static int dmSaveTimelineEventParam(DMResource *res, const DMTimelineEventParam *param)
 {
     int err;
     DMFTimelineEventParam hdr;
     Uint16 len;
 
     strncpy(hdr.name, param->name, sizeof(hdr.name));
+    hdr.name[sizeof(hdr.name) - 1] = 0;
     hdr.type = param->type;
 
     if (!dmf_write_str(res, hdr.name, sizeof(hdr.name)) ||
@@ -124,12 +125,14 @@
 }
 
 
-static int dmSaveTimelineEvent(DMResource *res, DMTimelineEvent *event)
+static int dmSaveTimelineEvent(DMResource *res, const DMTimelineEvent *event)
 {
     int param, err;
     DMFTimelineEvent hdr;
 
     strncpy(hdr.effectName, event->effect->name, sizeof(hdr.effectName));
+    hdr.effectName[sizeof(hdr.effectName) - 1] = 0;
+
     hdr.start    = event->start;
     hdr.duration = event->duration;
     hdr.nparams  = event->nparams;
@@ -150,12 +153,13 @@
 }
 
 
-static int dmSaveTimelineTrack(DMResource *res, DMTimelineTrack *track)
+static int dmSaveTimelineTrack(DMResource *res, const DMTimelineTrack *track)
 {
     int event, err;
     DMFTimelineTrack hdr;
 
     strncpy(hdr.name, track->name, sizeof(hdr.name));
+    hdr.name[sizeof(hdr.name) - 1] = 0;
 
     if (!dmf_write_le32(res, track->index) ||
         !dmf_write_le32(res, track->layer) ||
@@ -177,13 +181,15 @@
 }
 
 
-int dmSaveTimeline(DMResource *res, DMTimeline *tl)
+int dmSaveTimeline(DMResource *res, const DMTimeline *tl)
 {
     int track, err;
     DMFTimeline hdr;
 
     memcpy(&hdr.magic, DT_MAGIC_ID, sizeof(hdr.magic));
     strncpy(hdr.name, tl->name, sizeof(hdr.name));
+    hdr.name[sizeof(hdr.name) - 1] = 0;
+
     hdr.ntracks = tl->ntracks;
     hdr.duration = tl->duration;