You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Define Py_VA_COPY macro as a cross-platform replacement for gcc __va_copy #46695
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/abalkin'closed_at=<Date2010-08-11.22:12:59.423>created_at=<Date2008-03-21.10:27:37.295>labels= ['interpreter-core', 'type-feature']
title='Define Py_VA_COPY macro as a cross-platform replacement for gcc __va_copy'updated_at=<Date2010-08-11.22:12:59.422>user='https://bugs.python.org/rolland'
memcpy() is accessing va_list before it is initialized.
Before the first access to a va_list type variable, and after the last
access to that variable, calls to va_start() and va_end() must be made
to initialize and free the variable.
Such behaviour should be corrected in the following files :
This is not a bug. All the reported functions expect va_list argument
to be initialized before being called. AFAICT, they are consistently
used in this way. For example,
/* count the args */va_start(vargs, callable);
args=objargs_mktuple(vargs);
va_end(vargs);
if (args==NULL)
returnNULL;
tmp=PyObject_Call(callable, args, NULL);
Py_DECREF(args);
returntmp;
}
This may need to be clarified in the docs. For example, PyString_FromFormatV does not mention that vargs needs to be
initialized: <http://docs.python.org/dev/c-
api/string.html#PyString_FromFormatV>. On the other hand, this may be
obvious to most C programmers.
On the second thought the macro dance highlighted by OP belongs to
pyport.h. Attached patch defines Py_VA_COPY macro and uses it to simplify
va_list copying code.
changed the title [-]uninitialized access to va_list[/-][+]Define Py_VA_COPY macro as a cross-platform replacement for gcc __va_copy[/+]on Mar 25, 2008
This is what I meant. The initialization should be done by calling
va_start(count_va); as you described.
In the files and lines I reported though, this is not called.
I'll file a patch for it soon.
--Rolland Dudemaine
This is not a bug. All the reported functions expect va_list argument
to be initialized before being called. AFAICT, they are consistently
used in this way. For example,
This may need to be clarified in the docs. For example, PyString_FromFormatV does not mention that vargs needs to be
initialized: <http://docs.python.org/dev/c-
api/string.html#PyString_FromFormatV>. On the other hand, this may be
obvious to most C programmers.
changed the title [-]Define Py_VA_COPY macro as a cross-platform replacement for gcc __va_copy[/-][+]uninitialized access to va_list[/+]on Mar 25, 2008
rolland commented on Mar 27, 2008
rollandmannequin
MannequinAuthor
More actions
Actually, this thing is more complex to solve than I thought.
Specifically, as described in http://www.opengroup.org/onlinepubs/007908775/xsh/stdarg.h.html stdarg
requires that variable argument functions have at least one fixed argument.
This is implied by the declaration of "void va_start(va_list ap, argN);".
As explained in the original ticket description, and also described
before in the above link, va_start() must be called before any call to
va_arg(), and this includes any access to the argument list using
__va_copy namely.
The problem is that at least objargs_mktuple(), line 2649 of Objects/abstract.c does not have a first fixed argument.
The va_list is initialized by the function that calls objargs_mktuple.
va_start() and va_end() need to be called in the function that takes
"..." as a parameter, and it is.
Not a bug, but +1 on Alexander's patch to consolidate all the #ifdef's
for cleanliness.
changed the title [-]uninitialized access to va_list[/-][+]Define Py_VA_COPY macro as a cross-platform replacement for gcc __va_copy[/+]on Feb 24, 2010
Activity
rolland commentedon Mar 21, 2008
...
memcpy() is accessing va_list before it is initialized.
Before the first access to a va_list type variable, and after the last
access to that variable, calls to va_start() and va_end() must be made
to initialize and free the variable.
Such behaviour should be corrected in the following files :
tiran commentedon Mar 21, 2008
Can you provide a patch for 2.6 against the latest svn checkout of the
trunk please?
abalkin commentedon Mar 25, 2008
This is not a bug. All the reported functions expect va_list argument
to be initialized before being called. AFAICT, they are consistently
used in this way. For example,
This may need to be clarified in the docs. For example, PyString_FromFormatV does not mention that vargs needs to be
initialized: <http://docs.python.org/dev/c-
api/string.html#PyString_FromFormatV>. On the other hand, this may be
obvious to most C programmers.
I suggest to close this issue as invalid.
abalkin commentedon Mar 25, 2008
On the second thought the macro dance highlighted by OP belongs to
pyport.h. Attached patch defines Py_VA_COPY macro and uses it to simplify
va_list copying code.
tiran commentedon Mar 25, 2008
Looks like a good idea to me
[-]uninitialized access to va_list[/-][+]Define Py_VA_COPY macro as a cross-platform replacement for gcc __va_copy[/+]rolland commentedon Mar 25, 2008
This is what I meant. The initialization should be done by calling
va_start(count_va); as you described.
In the files and lines I reported though, this is not called.
I'll file a patch for it soon.
--Rolland Dudemaine
Alexander Belopolsky wrote:
[-]Define Py_VA_COPY macro as a cross-platform replacement for gcc __va_copy[/-][+]uninitialized access to va_list[/+]rolland commentedon Mar 27, 2008
Actually, this thing is more complex to solve than I thought.
Specifically, as described in
http://www.opengroup.org/onlinepubs/007908775/xsh/stdarg.h.html stdarg
requires that variable argument functions have at least one fixed argument.
This is implied by the declaration of "void va_start(va_list ap, argN);".
As explained in the original ticket description, and also described
before in the above link, va_start() must be called before any call to
va_arg(), and this includes any access to the argument list using
__va_copy namely.
The problem is that at least objargs_mktuple(), line 2649 of
Objects/abstract.c does not have a first fixed argument.
benjaminp commentedon Jul 31, 2008
What's the status of this?
stutzbach commentedon Mar 30, 2009
Rolland,
The va_list is initialized by the function that calls objargs_mktuple.
va_start() and va_end() need to be called in the function that takes
"..." as a parameter, and it is.
Not a bug, but +1 on Alexander's patch to consolidate all the #ifdef's
for cleanliness.
bitdancer commentedon May 31, 2009
Reducing the priority and updating the target releases, since from the
discussion there doesn't appear to be a bug here.
AlexanderBelopolsky commentedon Feb 24, 2010
Updated the patch. In a year one more copy of va_copy macro dance have cropped in. Any reason this is still languishing?
AlexanderBelopolsky commentedon Feb 24, 2010
Rolland,
Please don't revert the title. The consensus is that there is no uninitialized access to va_list.
[-]uninitialized access to va_list[/-][+]Define Py_VA_COPY macro as a cross-platform replacement for gcc __va_copy[/+]pitrou commentedon Aug 11, 2010
Looks like a good idea. Don't other compilers have __va_copy equivalents?
Apparently, C99 defines va_copy(), which we could use conditionally.
abalkin commentedon Aug 11, 2010
I updated the patch for 3.x. I agree that using va_copy where available makes sense, but let's leave this type of improvements for the future.
abalkin commentedon Aug 11, 2010
Committed in r83949.