* Mathieu Desnoyers ([email protected]) wrote: > * Julien Desfossez ([email protected]) wrote: [...] > > +static int create_index_file(struct lttng_consumer_stream *stream) > > +{ > > + char *index_name; > > + struct lttng_packet_index_file_hdr hdr; > > + int ret; > > + > > + ret = asprintf(&index_name, "%s.idx", stream->name); > > + if (ret < 0) { > > + PERROR("Allocating index name"); > > + goto error; > > + } > > + ret = utils_create_stream_file(stream->chan->pathname, > > + index_name, 0, 0, stream->uid, > > + stream->gid); > > + free(index_name); > > + if (ret < 0) { > > + goto error; > > + } > > + > > + stream->index_fd = ret; > > + strncpy(hdr.magic, INDEX_MAGIC, sizeof(hdr.magic)); > > If you use strncpy, it's because you don't trust that INDEX_MAGIC will > always fit within hdr.magic. If it is the case, then you should always > do: > > hdr.magic[sizeof(hdr.magic) - 1] = '\0'; > > after the strncpy.
In this case, you'll want to use a memcpy, since you clearly copy from a fixed-sized to a fixed-sized area, which need to have both the same size. memcpy(hdr.magic, INDEX_MAGIC, sizeof(hdr.magic)); Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
