Skip to content

Commit 1cd7998

Browse files
committed
tccmacho: avoid warnings with strncpy and always terminate the target string
1 parent 0241120 commit 1cd7998

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tccmacho.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ static void * add_lc(struct macho *mo, uint32_t cmd, uint32_t cmdsize)
262262
static struct segment_command_64 * add_segment(struct macho *mo, const char *name)
263263
{
264264
struct segment_command_64 *sc = add_lc(mo, LC_SEGMENT_64, sizeof(*sc));
265-
strncpy(sc->segname, name, 16);
265+
strncpy(sc->segname, name, 16-1);
266+
sc->segname[16-1] = '\0';
266267
mo->seg2lc[mo->nseg++] = mo->nlc - 1;
267268
return sc;
268269
}
@@ -282,7 +283,8 @@ static int add_section(struct macho *mo, struct segment_command_64 **_seg, const
282283
seg = tcc_realloc(seg, sizeof(*seg) + seg->nsects * sizeof(*sec));
283284
sec = (struct section_64*)((char*)seg + sizeof(*seg)) + ret;
284285
memset(sec, 0, sizeof(*sec));
285-
strncpy(sec->sectname, name, 16);
286+
strncpy(sec->sectname, name, 16-1);
287+
sec->sectname[16-1] = '\0';
286288
strncpy(sec->segname, seg->segname, 16);
287289
*_seg = seg;
288290
return ret;

0 commit comments

Comments
 (0)