Commit 8f759ac0b373eea9dcec680524a68a527d637937

Vicent Marti 2014-08-07T18:00:57

Merge pull request #2471 from jacquesg/compatibility-cleanup Compatibility/Portability cleanup

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
diff --git a/src/clone.c b/src/clone.c
index 523b1fe..7835be1 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -488,6 +488,9 @@ static const char *repository_base(git_repository *repo)
 static bool can_link(const char *src, const char *dst, int link)
 {
 #ifdef GIT_WIN32
+	GIT_UNUSED(src);
+	GIT_UNUSED(dst);
+	GIT_UNUSED(link);
 	return false;
 #else
 
diff --git a/src/global.c b/src/global.c
index c72bfe8..f89c732 100644
--- a/src/global.c
+++ b/src/global.c
@@ -19,7 +19,9 @@ git_mutex git__mwindow_mutex;
 #ifdef GIT_SSL
 # include <openssl/ssl.h>
 SSL_CTX *git__ssl_ctx;
+# ifdef GIT_THREADS
 static git_mutex *openssl_locks;
+# endif
 #endif
 
 static git_global_shutdown_fn git__shutdown_callbacks[MAX_SHUTDOWN_CB];
diff --git a/src/path.h b/src/path.h
index b100af9..2e86241 100644
--- a/src/path.h
+++ b/src/path.h
@@ -8,6 +8,7 @@
 #define INCLUDE_path_h__
 
 #include "common.h"
+#include "posix.h"
 #include "buffer.h"
 #include "vector.h"
 
diff --git a/src/posix.h b/src/posix.h
index 965cd98..9ef3487 100644
--- a/src/posix.h
+++ b/src/posix.h
@@ -12,23 +12,61 @@
 #include <time.h>
 #include "fnmatch.h"
 
+/* stat: file mode type testing macros */
 #ifndef S_IFGITLINK
 #define S_IFGITLINK 0160000
 #define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
 #endif
 
+#ifndef S_IFLNK
+#define S_IFLNK 0120000
+#undef _S_IFLNK
+#define _S_IFLNK S_IFLNK
+#endif
+
+#ifndef S_IXUSR
+#define S_IXUSR 00100
+#endif
+
+#ifndef S_ISLNK
+#define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
+#endif
+
+#ifndef S_ISDIR
+#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
+#endif
+
+#ifndef S_ISREG
+#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
+#endif
+
+#ifndef S_ISFIFO
+#define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO)
+#endif
+
 /* if S_ISGID is not defined, then don't try to set it */
 #ifndef S_ISGID
 #define S_ISGID 0
 #endif
 
-#if !defined(O_BINARY)
+#ifndef O_BINARY
 #define O_BINARY 0
 #endif
-#if !defined(O_CLOEXEC)
+#ifndef O_CLOEXEC
 #define O_CLOEXEC 0
 #endif
 
+/* access() mode parameter #defines	*/
+#ifndef F_OK
+#define F_OK 0 /* existence check */
+#endif
+#ifndef W_OK
+#define W_OK 2 /* write mode check */
+#endif
+#ifndef R_OK
+#define R_OK 4 /* read mode check */
+#endif
+
 /* Determine whether an errno value indicates that a read or write failed
  * because the descriptor is blocked.
  */
@@ -38,6 +76,12 @@
 #define GIT_ISBLOCKED(e) ((e) == EAGAIN)
 #endif
 
+/* define some standard errnos that the runtime may be missing.  for example,
+ * mingw lacks EAFNOSUPPORT. */
+#ifndef EAFNOSUPPORT
+#define EAFNOSUPPORT (INT_MAX-1)
+#endif
+
 typedef int git_file;
 
 /**
@@ -56,8 +100,6 @@ typedef int git_file;
 extern int p_read(git_file fd, void *buf, size_t cnt);
 extern int p_write(git_file fd, const void *buf, size_t cnt);
 
-#define p_fstat(f,b) fstat(f, b)
-#define p_lseek(f,n,w) lseek(f, n, w)
 #define p_close(fd) close(fd)
 #define p_umask(m) umask(m)
 
@@ -66,30 +108,6 @@ extern int p_creat(const char *path, mode_t mode);
 extern int p_getcwd(char *buffer_out, size_t size);
 extern int p_rename(const char *from, const char *to);
 
-#ifndef GIT_WIN32
-
-#define p_stat(p,b) stat(p, b)
-#define p_chdir(p) chdir(p)
-#define p_rmdir(p) rmdir(p)
-#define p_chmod(p,m) chmod(p, m)
-#define p_access(p,m) access(p,m)
-#define p_ftruncate(fd, sz) ftruncate(fd, sz)
-#define p_recv(s,b,l,f) recv(s,b,l,f)
-#define p_send(s,b,l,f) send(s,b,l,f)
-typedef int GIT_SOCKET;
-#define INVALID_SOCKET -1
-
-#define p_localtime_r localtime_r
-#define p_gmtime_r gmtime_r
-
-#else
-
-typedef SOCKET GIT_SOCKET;
-extern struct tm * p_localtime_r (const time_t *timer, struct tm *result);
-extern struct tm * p_gmtime_r (const time_t *timer, struct tm *result);
-
-#endif
-
 /**
  * Platform-dependent methods
  */
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index bd9509c..32641cd 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -36,6 +36,10 @@
 #define CACHED_POST_BODY_BUF_SIZE	4096
 #define UUID_LENGTH_CCH	32
 
+#ifndef WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH
+#define WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH 0
+#endif
+
 static const char *prefix_http = "http://";
 static const char *prefix_https = "https://";
 static const char *upload_pack_service = "upload-pack";
@@ -745,9 +749,9 @@ replay:
 
 		/* Verify that we got the correct content-type back */
 		if (post_verb == s->verb)
-			snprintf(expected_content_type_8, MAX_CONTENT_TYPE_LEN, "application/x-git-%s-result", s->service);
+			p_snprintf(expected_content_type_8, MAX_CONTENT_TYPE_LEN, "application/x-git-%s-result", s->service);
 		else
-			snprintf(expected_content_type_8, MAX_CONTENT_TYPE_LEN, "application/x-git-%s-advertisement", s->service);
+			p_snprintf(expected_content_type_8, MAX_CONTENT_TYPE_LEN, "application/x-git-%s-advertisement", s->service);
 
 		if (git__utf8_to_16(expected_content_type, MAX_CONTENT_TYPE_LEN, expected_content_type_8) < 0) {
 			giterr_set(GITERR_OS, "Failed to convert expected content-type to wide characters");
diff --git a/src/unix/posix.h b/src/unix/posix.h
index 1e41bcf..e4f3ac6 100644
--- a/src/unix/posix.h
+++ b/src/unix/posix.h
@@ -4,33 +4,47 @@
  * This file is part of libgit2, distributed under the GNU GPL v2 with
  * a Linking Exception. For full terms see the included COPYING file.
  */
-#ifndef INCLUDE_posix__w32_h__
-#define INCLUDE_posix__w32_h__
+#ifndef INCLUDE_posix__unix_h__
+#define INCLUDE_posix__unix_h__
 
 #include <stdio.h>
 #include <sys/param.h>
 
+typedef int GIT_SOCKET;
+#define INVALID_SOCKET -1
+
+#define p_lseek(f,n,w) lseek(f, n, w)
+#define p_fstat(f,b) fstat(f, b)
 #define p_lstat(p,b) lstat(p,b)
+#define p_stat(p,b) stat(p, b)
+
 #define p_readlink(a, b, c) readlink(a, b, c)
 #define p_symlink(o,n) symlink(o, n)
 #define p_link(o,n) link(o, n)
 #define p_unlink(p) unlink(p)
 #define p_mkdir(p,m) mkdir(p, m)
 #define p_fsync(fd) fsync(fd)
+extern char *p_realpath(const char *, char *);
 
-/* The OpenBSD realpath function behaves differently */
-#if !defined(__OpenBSD__)
-# define p_realpath(p, po) realpath(p, po)
-#else
-char *p_realpath(const char *, char *);
-#endif
+#define p_recv(s,b,l,f) recv(s,b,l,f)
+#define p_send(s,b,l,f) send(s,b,l,f)
+#define p_inet_pton(a, b, c) inet_pton(a, b, c)
 
+#define p_strcasecmp(s1, s2) strcasecmp(s1, s2)
+#define p_strncasecmp(s1, s2, c) strncasecmp(s1, s2, c)
 #define p_vsnprintf(b, c, f, a) vsnprintf(b, c, f, a)
 #define p_snprintf(b, c, f, ...) snprintf(b, c, f, __VA_ARGS__)
 #define p_mkstemp(p) mkstemp(p)
-#define p_inet_pton(a, b, c) inet_pton(a, b, c)
+#define p_chdir(p) chdir(p)
+#define p_chmod(p,m) chmod(p, m)
+#define p_rmdir(p) rmdir(p)
+#define p_access(p,m) access(p,m)
+#define p_ftruncate(fd, sz) ftruncate(fd, sz)
 
 /* see win32/posix.h for explanation about why this exists */
 #define p_lstat_posixly(p,b) lstat(p,b)
 
+#define p_localtime_r(c, r) localtime_r(c, r)
+#define p_gmtime_r(c, r) gmtime_r(c, r)
+
 #endif
diff --git a/src/unix/realpath.c b/src/unix/realpath.c
index 15601bd..2e49150 100644
--- a/src/unix/realpath.c
+++ b/src/unix/realpath.c
@@ -6,7 +6,7 @@
  */
 #include <git2/common.h>
 
-#ifdef __OpenBSD__
+#ifndef GIT_WIN32
 
 #include <limits.h>
 #include <stdlib.h>
@@ -16,15 +16,16 @@
 char *p_realpath(const char *pathname, char *resolved)
 {
 	char *ret;
-
 	if ((ret = realpath(pathname, resolved)) == NULL)
 		return NULL;
 
-	/* Figure out if the file exists */
-	if (!access(ret, F_OK))
-		return ret;
-
-	return NULL;
+#ifdef __OpenBSD__
+	/* The OpenBSD realpath function behaves differently,
+	 * figure out if the file exists */
+	if (access(ret, F_OK) < 0)
+		ret = NULL;
+#endif
+	return ret;
 }
 
 #endif
diff --git a/src/win32/mingw-compat.h b/src/win32/mingw-compat.h
index 059e39c..83ee287 100644
--- a/src/win32/mingw-compat.h
+++ b/src/win32/mingw-compat.h
@@ -9,18 +9,11 @@
 
 #if defined(__MINGW32__)
 
-/* use a 64-bit file offset type */
-# undef lseek
-# define lseek _lseeki64
-# undef stat
-# define stat _stati64
-# undef fstat
-# define fstat _fstati64
-
-/* stat: file mode type testing macros */
-# define _S_IFLNK 0120000
-# define S_IFLNK _S_IFLNK
-# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
+#if _WIN32_WINNT >= 0x0601
+#define stat __stat64
+#else
+#define stat _stati64
+#endif
 
 #endif
 
diff --git a/src/win32/msvc-compat.h b/src/win32/msvc-compat.h
index fa4e291..4789d63 100644
--- a/src/win32/msvc-compat.h
+++ b/src/win32/msvc-compat.h
@@ -9,41 +9,12 @@
 
 #if defined(_MSC_VER)
 
-/* access() mode parameter #defines	*/
-#	define F_OK 0 /* existence check */
-#	define W_OK 2 /* write mode check */
-#	define R_OK 4 /* read mode check */
+/* 64-bit stat information, regardless of USE_32BIT_TIME_T define */
+#define stat __stat64
 
-#	define lseek _lseeki64
-#	define stat __stat64
-#	define fstat _fstat64
-
-/* stat: file mode type testing macros */
-#	define _S_IFLNK 0120000
-#	define S_IFLNK _S_IFLNK
-#	define S_IXUSR 00100
-
-#	define S_ISDIR(m)	(((m) & _S_IFMT) == _S_IFDIR)
-#	define S_ISREG(m)	(((m) & _S_IFMT) == _S_IFREG)
-#	define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO)
-#	define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
-
-#	define mode_t unsigned short
-
-/* case-insensitive string comparison */
-#	define strcasecmp	_stricmp
-#	define strncasecmp _strnicmp
-
-/* MSVC doesn't define ssize_t at all */
+typedef unsigned short mode_t;
 typedef SSIZE_T ssize_t;
 
-/* define snprintf using variadic macro support if available */
-#if _MSC_VER >= 1500
-# define snprintf(BUF, SZ, FMT, ...) _snprintf_s(BUF, SZ, _TRUNCATE, FMT, __VA_ARGS__)
-#else
-# define snprintf _snprintf
-#endif
-
 #endif
 
 #define GIT_STDLIB_CALL __cdecl
diff --git a/src/win32/posix.h b/src/win32/posix.h
index 22ea6a5..e055a77 100644
--- a/src/win32/posix.h
+++ b/src/win32/posix.h
@@ -12,49 +12,35 @@
 #include "utf-conv.h"
 #include "dir.h"
 
-/* define some standard errnos that the runtime may be missing.  for example,
- * mingw lacks EAFNOSUPPORT. */
+typedef SOCKET GIT_SOCKET;
 
-#ifndef EAFNOSUPPORT
-# define EAFNOSUPPORT (INT_MAX-1)
-#endif
-
-#if defined(_MSC_VER) && _MSC_VER >= 1500
-# define p_ftruncate(fd, sz) _chsize_s(fd, sz)
-#else  /* MinGW */
-# define p_ftruncate(fd, sz) _chsize(fd, sz)
-#endif
-
-GIT_INLINE(int) p_link(const char *old, const char *new)
-{
-	GIT_UNUSED(old);
-	GIT_UNUSED(new);
-	errno = ENOSYS;
-	return -1;
-}
-
-extern int p_mkdir(const char *path, mode_t mode);
-extern int p_unlink(const char *path);
+#define p_lseek(f,n,w) _lseeki64(f, n, w)
+#define p_fstat(f,b) _fstat64(f, b)
 extern int p_lstat(const char *file_name, struct stat *buf);
+extern int p_stat(const char* path, struct stat* buf);
+
 extern int p_readlink(const char *path, char *buf, size_t bufsiz);
 extern int p_symlink(const char *old, const char *new);
+extern int p_link(const char *old, const char *new);
+extern int p_unlink(const char *path);
+extern int p_mkdir(const char *path, mode_t mode);
+extern int p_fsync(int fd);
 extern char *p_realpath(const char *orig_path, char *buffer);
+
+extern int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags);
+extern int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags);
+extern int p_inet_pton(int af, const char* src, void* dst);
+
+#define strcasecmp(s1, s2) _stricmp(s1, s2)
+#define strncasecmp(s1, s2, c) _strnicmp(s1, s2, c)
 extern int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr);
 extern int p_snprintf(char *buffer, size_t count, const char *format, ...) GIT_FORMAT_PRINTF(3, 4);
 extern int p_mkstemp(char *tmp_path);
-extern int p_stat(const char* path, struct stat* buf);
 extern int p_chdir(const char* path);
 extern int p_chmod(const char* path, mode_t mode);
 extern int p_rmdir(const char* path);
 extern int p_access(const char* path, mode_t mode);
-extern int p_fsync(int fd);
-extern int p_open(const char *path, int flags, ...);
-extern int p_creat(const char *path, mode_t mode);
-extern int p_getcwd(char *buffer_out, size_t size);
-extern int p_rename(const char *from, const char *to);
-extern int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags);
-extern int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags);
-extern int p_inet_pton(int af, const char* src, void* dst);
+extern int p_ftruncate(int fd, long size);
 
 /* p_lstat is almost but not quite POSIX correct.  Specifically, the use of
  * ENOTDIR is wrong, in that it does not mean precisely that a non-directory
@@ -64,4 +50,7 @@ extern int p_inet_pton(int af, const char* src, void* dst);
  */
 extern int p_lstat_posixly(const char *filename, struct stat *buf);
 
+extern struct tm * p_localtime_r (const time_t *timer, struct tm *result);
+extern struct tm * p_gmtime_r (const time_t *timer, struct tm *result);
+
 #endif
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index a74fcaa..0023f95 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -51,6 +51,15 @@ static int utf8_to_16_with_errno(git_win32_path dest, const char *src)
 	return len;
 }
 
+int p_ftruncate(int fd, long size)
+{
+#if defined(_MSC_VER) && _MSC_VER >= 1500
+	return _chsize_s(fd, size);
+#else
+	return _chsize(fd, size);
+#endif
+}
+
 int p_mkdir(const char *path, mode_t mode)
 {
 	git_win32_path buf;
@@ -63,6 +72,14 @@ int p_mkdir(const char *path, mode_t mode)
 	return _wmkdir(buf);
 }
 
+int p_link(const char *old, const char *new)
+{
+	GIT_UNUSED(old);
+	GIT_UNUSED(new);
+	errno = ENOSYS;
+	return -1;
+}
+
 int p_unlink(const char *path)
 {
 	git_win32_path buf;
@@ -547,11 +564,19 @@ char *p_realpath(const char *orig_path, char *buffer)
 
 int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr)
 {
-#if defined(_MSC_VER) && _MSC_VER >= 1500
+#if defined(_MSC_VER)
 	int len;
 
-	if (count == 0 ||
-		(len = _vsnprintf_s(buffer, count, _TRUNCATE, format, argptr)) < 0)
+	if (count == 0)
+		return _vscprintf(format, argptr);
+
+	#if _MSC_VER >= 1500
+	len = _vsnprintf_s(buffer, count, _TRUNCATE, format, argptr);
+	#else
+	len = _vsnprintf(buffer, count, format, argptr);
+	#endif
+
+	if (len < 0)
 		return _vscprintf(format, argptr);
 
 	return len;
diff --git a/tests/clar_libgit2.h b/tests/clar_libgit2.h
index 0744877..f515542 100644
--- a/tests/clar_libgit2.h
+++ b/tests/clar_libgit2.h
@@ -3,6 +3,7 @@
 
 #include "clar.h"
 #include <git2.h>
+#include <posix.h>
 #include "common.h"
 
 /**
@@ -51,7 +52,7 @@ GIT_INLINE(void) clar__assert_in_range(
 {
 	if (lo > val || hi < val) {
 		char buf[128];
-		snprintf(buf, sizeof(buf), "%d not in [%d,%d]", val, lo, hi);
+		p_snprintf(buf, sizeof(buf), "%d not in [%d,%d]", val, lo, hi);
 		clar__fail(file, line, err, buf, should_abort);
 	}
 }
diff --git a/tests/refs/pack.c b/tests/refs/pack.c
index 7f5c611..dbe377d 100644
--- a/tests/refs/pack.c
+++ b/tests/refs/pack.c
@@ -91,12 +91,12 @@ void test_refs_pack__symbolic(void)
 	/* make a bunch of references */
 
 	for (i = 0; i < 100; ++i) {
-		snprintf(name, sizeof(name), "refs/heads/symbolic-%03d", i);
+		p_snprintf(name, sizeof(name), "refs/heads/symbolic-%03d", i);
 		cl_git_pass(git_reference_symbolic_create(
 			&ref, g_repo, name, "refs/heads/master", 0, NULL, NULL));
 		git_reference_free(ref);
 
-		snprintf(name, sizeof(name), "refs/heads/direct-%03d", i);
+		p_snprintf(name, sizeof(name), "refs/heads/direct-%03d", i);
 		cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL, NULL));
 		git_reference_free(ref);
 	}
diff --git a/tests/stress/diff.c b/tests/stress/diff.c
index 3d20926..0dda44d 100644
--- a/tests/stress/diff.c
+++ b/tests/stress/diff.c
@@ -97,14 +97,14 @@ void test_stress_diff__rename_big_files(void)
 	cl_git_pass(git_repository_index(&index, g_repo));
 
 	for (i = 0; i < 100; i += 1) {
-		snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i);
+		p_snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i);
 		for (j = i * 256; j > 0; --j)
 			git_buf_printf(&b, "more content %d\n", i);
 		cl_git_mkfile(tmp, b.ptr);
 	}
 
 	for (i = 0; i < 100; i += 1) {
-		snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i);
+		p_snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i);
 		cl_git_pass(git_index_add_bypath(index, tmp + strlen("renames/")));
 	}
 
@@ -128,15 +128,15 @@ void test_stress_diff__rename_many_files(void)
 	git_buf_printf(&b, "%08d\n" ANOTHER_POEM "%08d\n" ANOTHER_POEM ANOTHER_POEM, 0, 0);
 
 	for (i = 0; i < 2500; i += 1) {
-		snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i);
-		snprintf(b.ptr, 9, "%08d", i);
+		p_snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i);
+		p_snprintf(b.ptr, 9, "%08d", i);
 		b.ptr[8] = '\n';
 		cl_git_mkfile(tmp, b.ptr);
 	}
 	git_buf_free(&b);
 
 	for (i = 0; i < 2500; i += 1) {
-		snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i);
+		p_snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i);
 		cl_git_pass(git_index_add_bypath(index, tmp + strlen("renames/")));
 	}
 
diff --git a/tests/threads/refdb.c b/tests/threads/refdb.c
index 94a21f2..078267a 100644
--- a/tests/threads/refdb.c
+++ b/tests/threads/refdb.c
@@ -58,7 +58,7 @@ void test_threads_refdb__iterator(void)
 	/* make a bunch of references */
 
 	for (r = 0; r < 200; ++r) {
-		snprintf(name, sizeof(name), "refs/heads/direct-%03d", r);
+		p_snprintf(name, sizeof(name), "refs/heads/direct-%03d", r);
 		cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL, NULL));
 		git_reference_free(ref);
 	}
@@ -102,7 +102,7 @@ static void *create_refs(void *arg)
 	cl_git_pass(git_reference_name_to_id(&head, g_repo, "HEAD"));
 
 	for (i = 0; i < 10; ++i) {
-		snprintf(name, sizeof(name), "refs/heads/thread-%03d-%02d", *id, i);
+		p_snprintf(name, sizeof(name), "refs/heads/thread-%03d-%02d", *id, i);
 		cl_git_pass(git_reference_create(&ref[i], g_repo, name, &head, 0, NULL, NULL));
 
 		if (i == 5) {
@@ -127,7 +127,7 @@ static void *delete_refs(void *arg)
 	char name[128];
 
 	for (i = 0; i < 10; ++i) {
-		snprintf(
+		p_snprintf(
 			name, sizeof(name), "refs/heads/thread-%03d-%02d", (*id) & ~0x3, i);
 
 		if (!git_reference_lookup(&ref, g_repo, name)) {
@@ -167,7 +167,7 @@ void test_threads_refdb__edit_while_iterate(void)
 	/* make a bunch of references */
 
 	for (r = 0; r < 50; ++r) {
-		snprintf(name, sizeof(name), "refs/heads/starter-%03d", r);
+		p_snprintf(name, sizeof(name), "refs/heads/starter-%03d", r);
 		cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL, NULL));
 		git_reference_free(ref);
 	}