History

tccmacho: avoid warnings with strncpy and always terminate the target string

Detlef Riekenberg committed 4 years ago

Commit 1cd79981 parent 02411201 file · +4 −2Browse files

Unified · Split

tccmacho.c+4−2
@@ -262,7 +262,8 @@ static void * add_lc(struct macho *mo, uint32_t cmd, uint32_t cmdsize) · 261 unmodified lines
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 · 13 unmodified lines
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;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t