diff Objects/stringobject.c @ 19486:5c859d2cb37b legacy-trunk

PyString_FromFormatV: Massage platform %p output to match what gcc does, at least in the first two characters. %p is ill-defined, and people will forever commit bad tests otherwise ("bad" in the sense that they fall over (at least on Windows) for lack of a leading '0x'; 5 of the 7 tests in test_repr.py failed on Windows for that reason this time around).
author Tim Peters <tim.peters@gmail.com>
date Sat, 25 Aug 2001 03:02:28 +0000
parents bc63afc701ef
children 3e74318a1b76
line wrap: on
line diff
--- a/Objects/stringobject.c	Fri Aug 24 19:46:21 2001 +0000
+++ b/Objects/stringobject.c	Sat Aug 25 03:02:28 2001 +0000
@@ -269,6 +269,14 @@
 				break;
 			case 'p':
 				sprintf(s, "%p", va_arg(vargs, void*));
+				/* %p is ill-defined:  ensure leading 0x. */
+				if (s[1] == 'X')
+					s[1] = 'x';
+				else if (s[1] != 'x') {
+					memmove(s+2, s, strlen(s)+1);
+					s[0] = '0';
+					s[1] = 'x';
+				}
 				s += strlen(s);
 				break;
 			case '%':