On Mon, Dec 8, 2014 at 9:04 PM, Nguyễn Thái Ngọc Duy <pclo...@gmail.com> wrote: > +void write_untracked_extension(struct strbuf *out, struct untracked_cache > *untracked) > +{ > + struct ondisk_untracked_cache *ouc; > + struct write_data wd; > + unsigned char varbuf[16]; > + int len = 0, varint_len; > + if (untracked->exclude_per_dir) > + len = strlen(untracked->exclude_per_dir); > + ouc = xmalloc(sizeof(*ouc) + len); > + stat_data_to_disk(&ouc->info_exclude_stat, > &untracked->ss_info_exclude.stat); > + stat_data_to_disk(&ouc->excludes_file_stat, > &untracked->ss_excludes_file.stat); > + hashcpy(ouc->info_exclude_sha1, untracked->ss_info_exclude.sha1); > + hashcpy(ouc->excludes_file_sha1, untracked->ss_excludes_file.sha1); > + ouc->dir_flags = htonl(untracked->dir_flags); > + memcpy(ouc->exclude_per_dir, untracked->exclude_per_dir, len + 1); > + strbuf_add(out, ouc, sizeof(*ouc) + len);
just fyi, this sizeof(*ouc) here is wrong because we write down an unknown number of padding by the compiler after the last field "char exclude_per_dir[1]". I will use offsetof(struct..., exclude_per_dir) next time. Spotted by valgrind. -- Duy -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html