[Asterisk-code-review] vector: multiple evaluation of elem in AST VECTOR ADD SORTED. (asterisk[15])

George Joseph asteriskteam at digium.com
Fri Oct 6 08:11:48 CDT 2017


George Joseph has posted comments on this change. ( https://gerrit.asterisk.org/6662 )

Change subject: vector: multiple evaluation of elem in AST_VECTOR_ADD_SORTED.
......................................................................


Patch Set 1: Code-Review-1

(3 comments)

https://gerrit.asterisk.org/#/c/6662/1/include/asterisk/vector.h
File include/asterisk/vector.h:

https://gerrit.asterisk.org/#/c/6662/1/include/asterisk/vector.h@307
PS1, Line 307:  * \param elem Element to insert.
\param elem Element to insert. MUST BE SCALAR or cast to a scalar.


https://gerrit.asterisk.org/#/c/6662/1/include/asterisk/vector.h@309
PS1, Line 309:  *
* \warning 'elem' must be scalar so passing 'x' where 'x' is defined as 'char x[4]' will fail to compile.  However casting 'x' as 'char *' does result in a scalar value and CAN be used.


https://gerrit.asterisk.org/#/c/6662/1/include/asterisk/vector.h@318
PS1, Line 318: 	typeof(elem) __elem = (elem); \
> what's happening is that if "elem" is an array say "char[4]",
 > the expression becomes...
 > char __elem[4] = (elem);
 > which is an assignment of an array to an array which isn't valid in
 > C.
 > 
 > You can do this however...
 > __auto_type __elem = (elem);
 > This automatically evaluates to...
 > char *__elem = (elem);
 > 
 > Unfortunately, __auto_type may be a recent addition to gcc and
 > clang so I'm testing with docker images to see how far back it
 > goes.

Not far enough it seems. :(
I think the best approach is to cast CCC2 to "char *" on line 213 of test_vector.c and add the qualifier to the doc that elem must be scalar or cast to a scalar.



-- 
To view, visit https://gerrit.asterisk.org/6662
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: comment
Gerrit-Change-Id: Ib960d7f5576f9e1a3c478ecb48995582a574e06d
Gerrit-Change-Number: 6662
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Comment-Date: Fri, 06 Oct 2017 13:11:48 +0000
Gerrit-HasComments: Yes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171006/018fc853/attachment.html>


More information about the asterisk-code-review mailing list