public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [Patch] Fix -Werror fallout in binutils/winduni.c (and fix a FIXME)
@ 2005-03-24 15:16 Danny Smith
  2005-03-24 16:46 ` Nick Clifton
  0 siblings, 1 reply; 5+ messages in thread
From: Danny Smith @ 2005-03-24 15:16 UTC (permalink / raw)
  To: binutils

With -Werror, I now  get error for unused variables 's' and 'w' in
binutils/winduni.c when _WIN32 is defined. The following patch fixes. It
also removes a FIXME that needs to be fixed on the way to providing
support for multibyte code pages on windows. 

No testsuite regressions.

Danny

ChangeLog
2005-03-24  Danny Smith  <dannysmith@users.sourceforge.net>

	* winduni.c (unicode_from_ascii): Don't declared variables
	's' and 'w' if _WIN32.  Use MultiByteToWideChar to set the unicode
	string len.

Index: winduni.c
===================================================================
RCS file: /cvs/src/src/binutils/winduni.c,v
retrieving revision 1.3
diff -c -3 -p -r1.3 winduni.c
*** winduni.c	14 Sep 2003 12:20:17 -0000	1.3
--- winduni.c	24 Mar 2005 10:29:50 -0000
*************** void
*** 43,67 ****
  unicode_from_ascii (int *length, unichar **unicode, const char *ascii)
  {
    int len;
    const char *s;
    unsigned short *w;
  
    len = strlen (ascii);
- 
-   if (length != NULL)
-     *length = len;
- 
    *unicode = ((unichar *) res_alloc ((len + 1) * sizeof (unichar)));
- 
- #ifdef _WIN32
-   /* FIXME: On Windows, we should be using MultiByteToWideChar to set
-      the length.  */
-   MultiByteToWideChar (CP_ACP, 0, ascii, len + 1, *unicode, len + 1);
- #else
    for (s = ascii, w = *unicode; *s != '\0'; s++, w++)
      *w = *s & 0xff;
    *w = 0;
  #endif
  }
  
  /* Print the unicode string UNICODE to the file E.  LENGTH is the
--- 43,74 ----
  unicode_from_ascii (int *length, unichar **unicode, const char *ascii)
  {
    int len;
+ #ifndef _WIN32
    const char *s;
    unsigned short *w;
  
    len = strlen (ascii);
    *unicode = ((unichar *) res_alloc ((len + 1) * sizeof (unichar)));
    for (s = ascii, w = *unicode; *s != '\0'; s++, w++)
      *w = *s & 0xff;
    *w = 0;
+ #else
+   /* We use  MultiByteToWideChar rather than strlen to get the unicode
+      string length to allow multibyte "ascii" chars. The value returned
+      by this function includes the trailing '\0'.  */
+   len = MultiByteToWideChar (CP_ACP, 0, ascii, -1, NULL, 0);
+   if (len)
+     {
+       *unicode = ((unichar *) res_alloc (len * sizeof (unichar)));
+       MultiByteToWideChar (CP_ACP, 0, ascii, -1, *unicode, len);
+     }
+   /* Discount the trailing '/0'.  If MultiByteToWideChar failed,
+      this will set *length to -1.  */
+   len--;
  #endif
+ 
+   if (length != NULL)
+     *length = len;
  }
  
  /* Print the unicode string UNICODE to the file E.  LENGTH is the

Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] Fix -Werror fallout in binutils/winduni.c (and fix a FIXME)
  2005-03-24 15:16 [Patch] Fix -Werror fallout in binutils/winduni.c (and fix a FIXME) Danny Smith
@ 2005-03-24 16:46 ` Nick Clifton
  2005-03-24 23:37   ` Danny Smith
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Clifton @ 2005-03-24 16:46 UTC (permalink / raw)
  To: dannysmith; +Cc: binutils

Hi Danny,

> 2005-03-24  Danny Smith  <dannysmith@users.sourceforge.net>
> 
> 	* winduni.c (unicode_from_ascii): Don't declared variables
> 	's' and 'w' if _WIN32.  Use MultiByteToWideChar to set the unicode
> 	string len.

Approved - please apply.

Cheers
   Nick

PS.  What configure target did you use to uncover this problem ?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] Fix -Werror fallout in binutils/winduni.c (and fix a FIXME)
  2005-03-24 16:46 ` Nick Clifton
@ 2005-03-24 23:37   ` Danny Smith
  2005-03-25  1:21     ` Nick Clifton
  0 siblings, 1 reply; 5+ messages in thread
From: Danny Smith @ 2005-03-24 23:37 UTC (permalink / raw)
  To: Nick Clifton, dannysmith; +Cc: binutils

Nick Clifton wrote:
> Hi Danny,
> 
>> 2005-03-24  Danny Smith  <dannysmith@users.sourceforge.net>
>> 
>> * winduni.c (unicode_from_ascii): Don't declared variables
>> 's' and 'w' if _WIN32.  Use MultiByteToWideChar to set the unicode
>> string len.
> 
> Approved - please apply.
> 
> Cheers
>    Nick
> 
> PS.  What configure target did you use to uncover this problem ?

i686-pc-mingw


Danny


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] Fix -Werror fallout in binutils/winduni.c (and fix a FIXME)
  2005-03-24 23:37   ` Danny Smith
@ 2005-03-25  1:21     ` Nick Clifton
  2005-03-25  1:22       ` Danny Smith
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Clifton @ 2005-03-25  1:21 UTC (permalink / raw)
  To: Danny Smith; +Cc: binutils

Hi Danny,

>>PS.  What configure target did you use to uncover this problem ?

> i686-pc-mingw

Err, I found that I had to use "i686-pc-mingw32".  Is there any difference ?

Cheers
   Nick


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] Fix -Werror fallout in binutils/winduni.c (and fix a FIXME)
  2005-03-25  1:21     ` Nick Clifton
@ 2005-03-25  1:22       ` Danny Smith
  0 siblings, 0 replies; 5+ messages in thread
From: Danny Smith @ 2005-03-25  1:22 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

Nick Clifton wrote:
> Hi Danny,
> 
>>> PS.  What configure target did you use to uncover this problem ?
> 
>> i686-pc-mingw
> 
> Err, I found that I had to use "i686-pc-mingw32".  Is there any difference ?
> 
No.  BTW, there are other Werror problems with mingw32,
I'll submit patches for some shortly, unless someone else does so first.   

Danny
> Cheers
>    Nick

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-03-24 21:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-24 15:16 [Patch] Fix -Werror fallout in binutils/winduni.c (and fix a FIXME) Danny Smith
2005-03-24 16:46 ` Nick Clifton
2005-03-24 23:37   ` Danny Smith
2005-03-25  1:21     ` Nick Clifton
2005-03-25  1:22       ` Danny Smith

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).