Skip to content
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

utils.c:utils_locale_to_utf8() specifies incorrect type for iconv_h #387

Open
paulsonx opened this issue Feb 24, 2021 · 0 comments
Open

Comments

@paulsonx
Copy link

 191 /* Convert from system locale string to UTF-8 */
 192 int
 193 utils_locale_to_utf8(const char *src, size_t is, char *dest, size_t os)
 194 {
 195         static iconv_t *iconv_h = (iconv_t) - 1;
 196         if (strncmp(g_codepage, "UTF-8", strlen("UTF-8")) == 0)
 197                 goto pass_trough_as_is;
 198 
 199         if (g_iconv_works == False)
 200                 goto pass_trough_as_is;
 201 
 202         /* if not already initialize */
 203         if (iconv_h == (iconv_t) - 1)
 204         {
 205                 if ((iconv_h = iconv_open("UTF-8", g_codepage)) == (iconv_t     ) - 1)
 206                 {
 207                         logger(Core, Warning,
 208                                "utils_string_to_utf8(), iconv_open[%s -> %s     ] fail %p", g_codepage,
 209                                "UTF-8", iconv_h);
 210 
 211                         g_iconv_works = False;
 212                         goto pass_trough_as_is;
 213                 }
 214         }
 215 
 216         /* convert string */
 217         if (iconv(iconv_h, (char **) &src, &is, &dest, &os) == (size_t) - 1     )     

The iconv_h variable represents a 'conversion descriptor' as returned by iconv_open(3) which
the man page describes as:

       #include <iconv.h>

       iconv_t iconv_open(const char *tocode, const char *fromcode);

DESCRIPTION
       The   iconv_open()   function  returns  a  conversion  descriptor  that
       describes a conversion from the codeset specified by the string pointed
       to  by  the  fromcode  argument  to the codeset specified by the string
       pointed to by the tocode argument. For state-dependent  encodings,  the
[...]
RETURN VALUES
       Upon successful completion iconv_open() returns a conversion descriptor
       for use on subsequent calls to iconv(). Otherwise, iconv_open() returns
       (iconv_t)  -1 and sets errno to indicate the error.

The current implementation specifies iconv_h as a pointer to a conversion descriptor
which the compiler flags as being incorrect for all subsequent uses where a regular
conversion descriptor is expected:

checking iconv.h usability... yes
checking iconv.h presence... yes
checking for iconv.h... yes
checking for iconv... yes
checking for iconv declaration...
         extern size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);

gcc -g -O2 -Wall -Wextra -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS    -I/usr/include/idn -D_REENTRANT -I/usr/include/PCSC  -D_REENTRANT  -DPACKAGE_NAME=\"rdesktop\" -DPACKAGE_TARNAME=\"rdesktop\" -DPACKAGE_VERSION=\"1.9.0\" -DPACKAGE_STRING=\"rdesktop\ 1.9.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DL_ENDIAN=1 -DHAVE_SYS_SELECT_H=1 -DHAVE_SYS_FILIO_H=1 -DHAVE_LOCALE_H=1 -DHAVE_LANGINFO_H=1 -DHAVE_SYSEXITS_H=1 -DHAVE_XRANDR=1 -DHAVE_XCURSOR=1 -DWITH_SCARD=1 -DWITH_PNP_NOTIFICATIONS=1 -DEGD_SOCKET=\"/var/run/egd-pool\" -DWITH_RDPSND=1 -DRDPSND_OSS=1 -DRDPSND_SUN=1 -DRDPSND_PULSE=1 -DHAVE_DIRENT_H=1 -DHAVE_DIRFD=1 -DHAVE_DECL_DIRFD=1 -DHAVE_ICONV_H=1 -DHAVE_ICONV=1 -DICONV_CONST= -DHAVE_SYS_VFS_H=1 -DHAVE_SYS_STATVFS_H=1 -DHAVE_SYS_STATFS_H=1 -DHAVE_SYS_PARAM_H=1 -DHAVE_SYS_MOUNT_H=1 -DSTAT_STATVFS64=1 -DHAVE_STRUCT_STATVFS_F_NAMEMAX=1 -DKEYMAP_PATH=\"/usr/local/share/rdesktop/keymaps/\" -o utils.o -c utils.c
utils.c: In function ‘utils_locale_to_utf8’:
utils.c:195:28: warning: initialization of ‘struct _iconv_info **’ from incompatible pointer type ‘struct _iconv_info *’ [-Wincompatible-pointer-types]
  195 |  static iconv_t *iconv_h = (iconv_t) - 1;
      |                            ^
utils.c:203:14: warning: comparison of distinct pointer types lacks a cast
  203 |  if (iconv_h == (iconv_t) - 1)
      |              ^~
utils.c:205:16: warning: assignment to ‘struct _iconv_info **’ from incompatible pointer type ‘iconv_t’ {aka ‘struct _iconv_info *’} [-Wincompatible-pointer-types]
  205 |   if ((iconv_h = iconv_open("UTF-8", g_codepage)) == (iconv_t) - 1)
      |                ^
utils.c:205:51: warning: comparison of distinct pointer types lacks a cast
  205 |   if ((iconv_h = iconv_open("UTF-8", g_codepage)) == (iconv_t) - 1)
      |                                                   ^~
utils.c:217:12: warning: passing argument 1 of ‘iconv’ from incompatible pointer type [-Wincompatible-pointer-types]
  217 |  if (iconv(iconv_h, (char **) &src, &is, &dest, &os) == (size_t) - 1)
      |            ^~~~~~~
      |            |
      |            struct _iconv_info **
In file included from utils.c:24:
/usr/include/iconv.h:97:21: note: expected ‘iconv_t’ {aka ‘struct _iconv_info *’} but argument is of type ‘struct _iconv_info **’
   97 | extern size_t iconv(iconv_t, char **_RESTRICT_KYWD,
      |                     ^~~~~~~
utils.c:219:15: warning: passing argument 1 of ‘iconv_close’ from incompatible pointer type [-Wincompatible-pointer-types]
  219 |   iconv_close(iconv_h);
      |               ^~~~~~~
      |               |
      |               struct _iconv_info **
In file included from utils.c:24:
/usr/include/iconv.h:76:24: note: expected ‘iconv_t’ {aka ‘struct _iconv_info *’} but argument is of type ‘struct _iconv_info **’
   76 | extern int iconv_close(iconv_t);
      |                        ^~~~~~~
utils.c:220:11: warning: assignment to ‘struct _iconv_info **’ from incompatible pointer type ‘struct _iconv_info *’ [-Wincompatible-pointer-types]
  220 |   iconv_h = (iconv_t) - 1;
      |           ^

The following one line change fixes this issue and allows the compiler to build utils.c
without any warnings or errors:

--- utils.c.orig        2021-02-24 11:29:33.902415585 +0000
+++ utils.c     2021-02-24 11:29:35.257966901 +0000
@@ -192,7 +192,7 @@
 int
 utils_locale_to_utf8(const char *src, size_t is, char *dest, size_t os)
 {
-       static iconv_t *iconv_h = (iconv_t) - 1;
+       static iconv_t iconv_h = (iconv_t) - 1;
        if (strncmp(g_codepage, "UTF-8", strlen("UTF-8")) == 0)
                goto pass_trough_as_is;
Ratio2 pushed a commit to Ratio2/vbox that referenced this issue Apr 7, 2021
include/iprt/x86.h: Undefine MSR_IA32_FLUSH_CMD to avoid warning about
'"MSR_IA32_FLUSH_CMD" redefined' when compiling SUPLibLdr.cpp.
SUPLibLdr.cpp includes <stdlib.h> which ultimately pulls in
<sys/controlregs.h> which has its own definition of MSR_IA32_FLUSH_CMD.

Additions/solaris/SharedFolders: Updated a handful of function prototypes
under SharedFolders/solaris10 which don't take any arguments to be
explicitly declared as 'function(void)' to silence gcc warnings from
-Wstrict-prototypes.

Main/src-server/solaris: Fixed two places where -Wconversion identified
possible alteration of the value due to different sized types.

RDP/client: Addressed an incorrect conversion descriptor type passed to
iconv(3C) in utils.c:utils_locale_to_utf8() (corresponding to unresolved
upstream issue #387 (rdesktop/rdesktop#387).
Tidied up some inconsistent iconv(3C) argument type usage: the use of
-D__USE_LEGACY_PROTOTYPES__ requires -DICONV_CONST=const.  Fixed some
incorrect strncpy()/strcat() calls using the corresponding code from
upstream.


git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@88297 cfe28804-0f27-0410-a406-dd0f0b0b656f
axbannaz pushed a commit to axbannaz/vbox that referenced this issue Apr 9, 2021
include/iprt/x86.h: Undefine MSR_IA32_FLUSH_CMD to avoid warning about
'"MSR_IA32_FLUSH_CMD" redefined' when compiling SUPLibLdr.cpp.
SUPLibLdr.cpp includes <stdlib.h> which ultimately pulls in
<sys/controlregs.h> which has its own definition of MSR_IA32_FLUSH_CMD.

Additions/solaris/SharedFolders: Updated a handful of function prototypes
under SharedFolders/solaris10 which don't take any arguments to be
explicitly declared as 'function(void)' to silence gcc warnings from
-Wstrict-prototypes.

Main/src-server/solaris: Fixed two places where -Wconversion identified
possible alteration of the value due to different sized types.

RDP/client: Addressed an incorrect conversion descriptor type passed to
iconv(3C) in utils.c:utils_locale_to_utf8() (corresponding to unresolved
upstream issue #387 (rdesktop/rdesktop#387).
Tidied up some inconsistent iconv(3C) argument type usage: the use of
-D__USE_LEGACY_PROTOTYPES__ requires -DICONV_CONST=const.  Fixed some
incorrect strncpy()/strcat() calls using the corresponding code from
upstream.


git-svn-id: http://www.virtualbox.org/svn/vbox/trunk@88297 cfe28804-0f27-0410-a406-dd0f0b0b656f
sergiomb2 pushed a commit to sergiomb2/VirtualBox that referenced this issue Apr 21, 2021
include/iprt/x86.h: Undefine MSR_IA32_FLUSH_CMD to avoid warning about
'"MSR_IA32_FLUSH_CMD" redefined' when compiling SUPLibLdr.cpp.
SUPLibLdr.cpp includes <stdlib.h> which ultimately pulls in
<sys/controlregs.h> which has its own definition of MSR_IA32_FLUSH_CMD.

Additions/solaris/SharedFolders: Updated a handful of function prototypes
under SharedFolders/solaris10 which don't take any arguments to be
explicitly declared as 'function(void)' to silence gcc warnings from
-Wstrict-prototypes.

Main/src-server/solaris: Fixed two places where -Wconversion identified
possible alteration of the value due to different sized types.

RDP/client: Addressed an incorrect conversion descriptor type passed to
iconv(3C) in utils.c:utils_locale_to_utf8() (corresponding to unresolved
upstream issue #387 (rdesktop/rdesktop#387).
Tidied up some inconsistent iconv(3C) argument type usage: the use of
-D__USE_LEGACY_PROTOTYPES__ requires -DICONV_CONST=const.  Fixed some
incorrect strncpy()/strcat() calls using the corresponding code from
upstream.


git-svn-id: http://www.virtualbox.org/svn/vbox@88297 cfe28804-0f27-0410-a406-dd0f0b0b656f
zzyuzzz added a commit to zzyuzzz/vboxgit that referenced this issue Jun 12, 2022
…----------------

r88297 | vboxsync | 2021-03-26 20:29:59 +0800 (Fri, 26 Mar 2021) | 23 lines

Some small Solaris-specific build warning fixes:

include/iprt/x86.h: Undefine MSR_IA32_FLUSH_CMD to avoid warning about
'"MSR_IA32_FLUSH_CMD" redefined' when compiling SUPLibLdr.cpp.
SUPLibLdr.cpp includes <stdlib.h> which ultimately pulls in
<sys/controlregs.h> which has its own definition of MSR_IA32_FLUSH_CMD.

Additions/solaris/SharedFolders: Updated a handful of function prototypes
under SharedFolders/solaris10 which don't take any arguments to be
explicitly declared as 'function(void)' to silence gcc warnings from
-Wstrict-prototypes.

Main/src-server/solaris: Fixed two places where -Wconversion identified
possible alteration of the value due to different sized types.

RDP/client: Addressed an incorrect conversion descriptor type passed to
iconv(3C) in utils.c:utils_locale_to_utf8() (corresponding to unresolved
upstream issue #387 (rdesktop/rdesktop#387).
Tidied up some inconsistent iconv(3C) argument type usage: the use of
-D__USE_LEGACY_PROTOTYPES__ requires -DICONV_CONST=const.  Fixed some
incorrect strncpy()/strcat() calls using the corresponding code from
upstream.

------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant