8000 bpo-36594: Fix incorrect use of %p in format strings by ZackerySpytz · Pull Request #12769 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-36594: Fix incorrect use of %p in format strings #12769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-36594: Fix incorrect use of %p in format strings
In addition, fix some other minor violations of C99.
  • Loading branch information
ZackerySpytz committed Apr 11, 2019
commit 2b41f005287254c317688238762ed807521920d1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix incorrect use of ``%p`` in format strings.
8 changes: 4 additions & 4 deletions Modules/_ctypes/_ctypes_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,23 @@ EXPORT(void)testfunc_array(int values[4])
EXPORT(long double)testfunc_Ddd(double a, double b)
{
long double result = (long double)(a * b);
printf("testfunc_Ddd(%p, %p)\n", &a, &b);
printf("testfunc_Ddd(%p, %p)\n", (void *)&a, (void *)&b);
printf("testfunc_Ddd(%g, %g)\n", a, b);
return result;
}

EXPORT(long double)testfunc_DDD(long double a, long double b)
{
long double result = a * b;
printf("testfunc_DDD(%p, %p)\n", &a, &b);
printf("testfunc_DDD(%p, %p)\n", (void *)&a, (void *)&b);
printf("testfunc_DDD(%Lg, %Lg)\n", a, b);
return result;
}

EXPORT(int)testfunc_iii(int a, int b)
{
int result = a * b;
printf("testfunc_iii(%p, %p)\n", &a, &b);
printf("testfunc_iii(%p, %p)\n", (void *)&a, (void *)&b);
return result;
}

Expand Down Expand Up @@ -361,7 +361,7 @@ static void _xxx_init(void *(*Xalloc)(int), void (*Xfree)(void *))
{
void *ptr;

printf("_xxx_init got %p %p\n", Xalloc, Xfree);
printf("_xxx_init got %p %p\n", (void *)Xalloc, (void *)Xfree);
printf("calling\n");
ptr = Xalloc(32);
Xfree(ptr);
Expand Down
4 changes: 2 additions & 2 deletions Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,11 @@ PyCArg_repr(PyCArgObject *self)
default:
if (is_literal_char((unsigned char)self->tag)) {
sprintf(buffer, "<cparam '%c' at %p>",
(unsigned char)self->tag, self);
(unsigned char)self->tag, (void *)self);
}
else {
sprintf(buffer, "<cparam 0x%02x at %p>",
(unsigned char)self->tag, self);
(unsigned char)self->tag, (void *)self);
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ _channel_finish_closing(struct _channel *chan) {
// Do the things that would have been done in _channels_close().
ref->chan = NULL;
_channel_free(chan);
};
}

/* "high"-level channel-related functions */

Expand Down
2 changes: 1 addition & 1 deletion Modules/faulthandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ void _PyFaulthandler_Fini(void)
#ifdef HAVE_SIGALTSTACK
if (stack.ss_sp != NULL) {
/* Fetch the current alt stack */
stack_t current_stack = {};
stack_t current_stack = {0};
if (sigaltstack(NULL, &current_stack) == 0) {
if (current_stack.ss_sp == stack.ss_sp) {
/* The current alt stack is the one that we installed.
Expand Down
2 changes: 1 addition & 1 deletion Modules/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ _Py_hashtable_print_stats(_Py_hashtable_t *ht)
}
printf("hash table %p: entries=%"
PY_FORMAT_SIZE_T "u/%" PY_FORMAT_SIZE_T "u (%.0f%%), ",
ht, ht->entries, ht->num_buckets, load * 100.0);
(void *)ht, ht->entries, ht->num_buckets, load * 100.0);
if (nchains)
printf("avg_chain_len=%.1f, ", (double)total_chain_len / nchains);
printf("max_chain_len=%" PY_FORMAT_SIZE_T "u, %" PY_FORMAT_SIZE_T "u KiB\n",
Expand Down
8 changes: 4 additions & 4 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
universally available */
Py_BEGIN_ALLOW_THREADS
fprintf(fp, "<refcnt %ld at %p>",
(long)op->ob_refcnt, op);
(long)op->ob_refcnt, (void *)op);
Py_END_ALLOW_THREADS
}
else {
Expand Down Expand Up @@ -478,7 +478,7 @@ _PyObject_Dump(PyObject* op)
"address : %p\n",
Py_TYPE(op)==NULL ? "NULL" : Py_TYPE(op)->tp_name,
(long)op->ob_refcnt,
op);
(void *)op);
fflush(stderr);
}

Expand Down Expand Up @@ -1871,7 +1871,7 @@ _Py_PrintReferences(FILE *fp)
PyObject *op;
fprintf(fp, "Remaining objects:\n");
for (op = refchain._ob_next; op != &refchain; op = op->_ob_next) {
fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] ", op, op->ob_refcnt);
fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] ", (void *)op, op->ob_refcnt);
if (PyObject_Print(op, fp, 0) != 0)
PyErr_Clear();
putc('\n', fp);
Expand All @@ -1887,7 +1887,7 @@ _Py_PrintReferenceAddresses(FILE *fp)
PyObject *op;
fprintf(fp, "Remaining object addresses:\n");
for (op = refchain._ob_next; op != &refchain; op = op->_ob_next)
fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] %s\n", op,
fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] %s\n", (void *)op,
op->ob_refcnt, Py_TYPE(op)->tp_name);
}

Expand Down
2 changes: 1 addition & 1 deletion Objects/obmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2337,7 +2337,7 @@ _PyObject_DebugDumpAddress(const void *p)
}

tail = q + nbytes;
fprintf(stderr, " The %d pad bytes at tail=%p are ", SST, tail);
fprintf(stderr, " The %d pad bytes at tail=%p are ", SST, (void *)tail);
ok = 1;
for (i = 0; i < SST; ++i) {
if (tail[i] != FORBIDDENBYTE) {
Expand Down
6 changes: 3 additions & 3 deletions Objects/unicodeobject.c
10000
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ void *_PyUnicode_compact_data(void *unicode_raw) {
}
void *_PyUnicode_data(void *unicode_raw) {
PyObject *unicode = _PyObject_CAST(unicode_raw);
printf("obj %p\n", unicode);
printf("obj %p\n", (void*)unicode);
printf("compact %d\n", PyUnicode_IS_COMPACT(unicode));
printf("compact ascii %d\n", PyUnicode_IS_COMPACT_ASCII(unicode));
printf("ascii op %p\n", ((void*)((PyASCIIObject*)(unicode) + 1)));
Expand Down Expand Up @@ -1249,14 +1249,14 @@ _PyUnicode_Dump(PyObject *op)

if (ascii->wstr == data)
printf("shared ");
printf("wstr=%p", ascii->wstr);
printf("wstr=%p", (void *)ascii->wstr);

if (!(ascii->state.ascii == 1 && ascii->state.compact == 1)) {
printf(" (%" PY_FORMAT_SIZE_T "u), ", compact->wstr_length);
if (!ascii->state.compact && compact->utf8 == unicode->data.any)
printf("shared ");
printf("utf8=%p (%" PY_FORMAT_SIZE_T "u)",
compact->utf8, compact->utf8_length);
(void *)compact->utf8, compact->utf8_length);
}
printf(", data=%p\n", data);
}
Expand Down
2 changes: 1 addition & 1 deletion Programs/_freeze_importlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ main(int argc, char *argv[])
size_t i, end = Py_MIN(n + 16, data_size);
fprintf(outfile, " ");
for (i = n; i < end; i++) {
fprintf(outfile, "%d,", (unsigned int) data[i]);
fprintf(outfile, "%u,", (unsigned int) data[i]);
}
fprintf(outfile, "\n");
}
Expand Down
8 changes: 4 additions & 4 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,7 @@ _alloc_preinit_entry(const wchar_t *value)

PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
return node;
};
}

static int
_append_preinit_entry(_Py_PreInitEntry *optionlist, const wchar_t *value)
Expand All @@ -1793,7 +1793,7 @@ _append_preinit_entry(_Py_PreInitEntry *optionlist, const wchar_t *value)
last_entry->next = new_entry;
}
return 0;
};
}

static void
_clear_preinit_entries(_Py_PreInitEntry *optionlist)
Expand All @@ -1810,7 +1810,7 @@ _clear_preinit_entries(_Py_PreInitEntry *optionlist)
current = next;
}
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
};
}

static void
_clear_all_preinit_options(void)
Expand Down Expand Up @@ -1841,7 +1841,7 @@ _PySys_ReadPreInitOptions(void)

_clear_all_preinit_options();
return 0;
};
}

static PyObject *
get_warnoptions(void)
Expand Down
4 changes: 2 additions & 2 deletions Python/thread_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ PyThread_allocate_lock(void)
}
}

dprintf(("PyThread_allocate_lock() -> %p\n", lock));
dprintf(("PyThread_allocate_lock() -> %p\n", (void *)lock));
return (PyThread_type_lock)lock;
}

Expand Down Expand Up @@ -521,7 +521,7 @@ PyThread_allocate_lock(void)
}
}

dprintf(("PyThread_allocate_lock() -> %p\n", lock));
dprintf(("PyThread_allocate_lock() -> %p\n", (void *)lock));
return (PyThread_type_lock) lock;
}

Expand Down
0