[Home]

Summary:ASTERISK-04282: [patch] wrong const in utils/astman.c
Reporter:Luigi Rizzo (rizzo)Labels:
Date Opened:2005-05-26 05:13:41Date Closed:2011-06-07 14:10:29
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Core/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) astman.diff
( 1) astman.diff.txt
Description:some variables in utils/astman.c are declared as const char *
They are clearly not const, as they are used as return values from
a function, and -Werror detects that.
Comments:By: Russell Bryant (russell) 2005-05-26 07:59:11

fixed in CVS HEAD

I had to add casts in the call to newtEntry since, at least on my system, it expects a (const char **)

Feel free to re-open if I messed something up.  Thanks!

By: Russell Bryant (russell) 2005-05-26 08:17:29

fixed in 1.0 as well

By: Luigi Rizzo (rizzo) 2005-05-26 09:54:43

not sure how to proceed here. On FreeBSD, newt version 0.51 has char ** as
the type of resultPtr. What version of newt do you have where it uses
const char ** ?

In any case the only cast that does not fail in both cases is "void *",
which is not nice to use, but possibly the only portable approach.

newtComponent newtEntry(int left, int top, const char * initialValue, int width,
                       char ** resultPtr, int flags);

By: Russell Bryant (russell) 2005-05-26 11:10:50

I have newt-0.51.6-5

in /usr/include/newt.h, I have ...

newtComponent newtEntry(int left, int top, const char * initialValue, int width, const char ** resultPtr, int flags);

By: Russell Bryant (russell) 2005-05-26 11:24:57

I have checked some other machines, all with some variant of newt-0.51, and they all have const char.  We could do something like in the attached patch if you want ...

By: Brian West (bkw918) 2005-05-26 13:01:37

I can't count the times this has fliped flopped...

I have changed it once.. it was changed back by another.

/b

By: Luigi Rizzo (rizzo) 2005-05-27 03:03:47

given that the issue goes back and forth, and given that it is a portability issue because platforms have different newtEntry definitions, possibly on different versions of linux as well, my suggestion would be the following:

- declare the variables as they should be i.e. const char *
 (the assumption is that only newt should play with those buffers)

- put the following block right before the first use of newtEntry

/*
* 2005.05.27 - different versions of newt define the type of the buffer
* (5th arguments) as char ** or const char ** . To let the code compile
* with -Werror, we cast it to void * through _NEWT_CAST.
*/
#define _NEWT_CAST   (void *)

- cast the argument as _NEWT_CAST in the calls to newtEntry()

Hopefully people will look up the definition of _NEWT_CAST, read the comment and avoid changing it again in the near future - I put a date in the comment so in due time the issue can be reconsidered.

By: Russell Bryant (russell) 2005-05-27 21:37:12

Ok, I have committed what you have suggested.  Hopefully that will make everyone happy.  :)

Thanks!

By: Digium Subversion (svnbot) 2008-01-15 15:36:07.000-0600

Repository: asterisk
Revision: 5770

U   trunk/utils/astman.c

------------------------------------------------------------------------
r5770 | russell | 2008-01-15 15:36:06 -0600 (Tue, 15 Jan 2008) | 2 lines

fix usage of const char (bug ASTERISK-4282)

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

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

By: Digium Subversion (svnbot) 2008-01-15 15:36:15.000-0600

Repository: asterisk
Revision: 5780

U   trunk/utils/astman.c

------------------------------------------------------------------------
r5780 | russell | 2008-01-15 15:36:15 -0600 (Tue, 15 Jan 2008) | 3 lines

hopefully the last commit to make things happy
across various versions of newt (bug ASTERISK-4282)

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

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

By: Digium Subversion (svnbot) 2008-01-15 15:36:16.000-0600

Repository: asterisk
Revision: 5781

U   branches/v1-0/astman/astman.c

------------------------------------------------------------------------
r5781 | russell | 2008-01-15 15:36:16 -0600 (Tue, 15 Jan 2008) | 3 lines

hopefully the last try at making this happy across
various versions of newt (bug ASTERISK-4282)

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

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