[Home]

Summary:ASTERISK-13261: Enumerated type and integer comparison do not work as you might expect
Reporter:Andrew Lindh (andrew)Labels:
Date Opened:2008-12-22 18:04:12.000-0600Date Closed:2008-12-22 22:34:09.000-0600
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Core/Channels
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:
Description:In main/channel.c there is a section of code (about line 2530):
+        if (condition < 0) {
+                /* Stop any tones that are playing */
+                ast_playtones_stop(chan);
+                return 0;
+        }

Where "condition" is an enumerated type. It seems logical that you can compare ordinal position of the value of variable (which is a number) to an integer, but it does not work. If the integer value of condition is -1 then the statement should evaluate as should be "true", but does is not (at least on my system). If you change the code to cast "condition" as an integer:
+        if ((int)condition < 0) {
then the comparison works as expected.



****** ADDITIONAL INFORMATION ******

Debian Linux GCC Version 4.1.2
This compiles without warnings and proves my point. GCC should warn about setting y without a cast, but I guess that would be like pascal and this is C...

#include <stdio.h>

int main()
{
       enum {A,B} y;

       y=(-1);

       printf("y = %d\n",y);
       if (y<0) printf("y < 0 is true\n"); else printf("y < 0 is false\n");
       if ((int)y<0) printf("(int)y < 0 is true\n"); else printf("(int)y < 0 is false\n");

       return(0);
}
Comments:By: Andrew Lindh (andrew) 2008-12-22 18:05:55.000-0600

Because of the problem, code that is expect to run is not executed... (oops, is this only a minor bug).

Another option would be to setup a new enumerator with the value of -1, that way you always have a value rather then some random integer.



By: Digium Subversion (svnbot) 2008-12-22 22:05:21.000-0600

Repository: asterisk
Revision: 166509

U   branches/1.4/main/channel.c

------------------------------------------------------------------------
r166509 | tilghman | 2008-12-22 22:05:21 -0600 (Mon, 22 Dec 2008) | 4 lines

Use the integer form of condition for integer comparisons.
(closes issue ASTERISK-13261)
Reported by: andrew

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=166509

By: Digium Subversion (svnbot) 2008-12-22 22:32:23.000-0600

Repository: asterisk
Revision: 166533

_U  trunk/
U   trunk/main/channel.c

------------------------------------------------------------------------
r166533 | tilghman | 2008-12-22 22:32:23 -0600 (Mon, 22 Dec 2008) | 11 lines

Merged revisions 166509 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
 r166509 | tilghman | 2008-12-22 22:05:25 -0600 (Mon, 22 Dec 2008) | 4 lines
 
 Use the integer form of condition for integer comparisons.
 (closes issue ASTERISK-13261)
  Reported by: andrew
........

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=166533

By: Digium Subversion (svnbot) 2008-12-22 22:33:32.000-0600

Repository: asterisk
Revision: 166534

_U  branches/1.6.0/
U   branches/1.6.0/main/channel.c

------------------------------------------------------------------------
r166534 | tilghman | 2008-12-22 22:33:32 -0600 (Mon, 22 Dec 2008) | 18 lines

Merged revisions 166533 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
 r166533 | tilghman | 2008-12-22 22:32:15 -0600 (Mon, 22 Dec 2008) | 11 lines
 
 Merged revisions 166509 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r166509 | tilghman | 2008-12-22 22:05:25 -0600 (Mon, 22 Dec 2008) | 4 lines
   
   Use the integer form of condition for integer comparisons.
   (closes issue ASTERISK-13261)
    Reported by: andrew
 ........
................

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=166534

By: Digium Subversion (svnbot) 2008-12-22 22:34:09.000-0600

Repository: asterisk
Revision: 166535

_U  branches/1.6.1/
U   branches/1.6.1/main/channel.c

------------------------------------------------------------------------
r166535 | tilghman | 2008-12-22 22:34:08 -0600 (Mon, 22 Dec 2008) | 18 lines

Merged revisions 166533 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
 r166533 | tilghman | 2008-12-22 22:32:15 -0600 (Mon, 22 Dec 2008) | 11 lines
 
 Merged revisions 166509 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r166509 | tilghman | 2008-12-22 22:05:25 -0600 (Mon, 22 Dec 2008) | 4 lines
   
   Use the integer form of condition for integer comparisons.
   (closes issue ASTERISK-13261)
    Reported by: andrew
 ........
................

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=166535