summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0001fc3)
raw | patch | inline | side by side (parent: 0001fc3)
author | Jonas Fonseca <fonseca@diku.dk> | |
Mon, 11 Sep 2006 01:12:15 +0000 (03:12 +0200) | ||
committer | Jonas Fonseca <fonseca@antimatter.localdomain> | |
Mon, 11 Sep 2006 01:39:36 +0000 (03:39 +0200) |
tig.c | patch | blob | history |
index d3702c4cb210e53429566ada6b7de1b49d3e5676..44fcb1b4f7a69db6054760c8fcc08dd47a410060 100644 (file)
--- a/tig.c
+++ b/tig.c
*/
static inline void
-string_ncopy(char *dst, const char *src, size_t dstlen)
+string_ncopy_do(char *dst, size_t dstlen, const char *src, size_t srclen)
{
- strncpy(dst, src, dstlen - 1);
- dst[dstlen - 1] = 0;
+ if (srclen > dstlen - 1)
+ srclen = dstlen - 1;
+ strncpy(dst, src, srclen);
+ dst[srclen] = 0;
}
-/* Shorthand for safely copying into a fixed buffer. */
+/* Shorthands for safely copying into a fixed buffer. */
+
#define string_copy(dst, src) \
- string_ncopy(dst, src, sizeof(dst))
+ string_ncopy_do(dst, sizeof(dst), src, sizeof(dst))
+
+#define string_ncopy(dst, src, srclen) \
+ string_ncopy_do(dst, sizeof(dst), src, srclen)
static char *
chomp_string(char *name)
string_copy(ref_commit, view->ref);
} else if (type == LINE_TREE_DIR || type == LINE_TREE_FILE) {
- strncpy(view->ref, text + STRING_SIZE("100644 blob "), 41);
- view->ref[40] = 0;
+ string_ncopy(view->ref, text + STRING_SIZE("100644 blob "), 40);
string_copy(ref_blob, view->ref);
}