Thread: Patch for VS.Net 2005's strxfrm() bug

Patch for VS.Net 2005's strxfrm() bug

From
"William ZHANG"
Date:
When I tried to compile pgsql-8.2devel with VS.Net 2005 and do regression
tests,
I found the problem. It's a bug inVS.Net 2005:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99694

--
With regards,
William ZHANG


begin 666 strxfrm.patch
M*BHJ('!G<W%L+6-V<VAE860M,C P-C W,C,O<W)C+V)A8VME;F0O=71I;',O
M861T+W-E;&9U;F-S+F,)1G)I($IU;" Q-" R,CHU,CHR-" R,# V"BTM+2!P
M9W-Q;"]S<F,O8F%C:V5N9"]U=&EL<R]A9'0O<V5L9G5N8W,N8PE-;VX@2G5L
M(#(T(# P.C,U.C4W(#(P,#8**BHJ*BHJ*BHJ*BHJ*BHJ"BHJ*B R.34V+#(Y
M-C(@*BHJ*@HM+2T@,CDU-BPR.3<Q("TM+2T*(" )"2 J(#T](&%S('EO=2=D
M(&5X<&5C="X@($-A;B=T(&%N>2!O9B!T:&5S92!P96]P;&4@<')O9W)A;2!T
M:&5I<B!W87D-"B @"0D@*B!O=70@;V8@82!P87!E<B!B86<_#0H@( D)("HO
M#0HK( D)+RH@:'1T<#HO+V-O;FYE8W0N;6EC<F]S;V9T+F-O;2]6:7-U86Q3
M='5D:6\O9F5E9&)A8VLO5FEE=T9E961B86-K+F%S<'@_1F5E9&)A8VM)1#TY
M.38Y-" J+PT**R C:68@7TU30U]615(@/3T@,30P, T**R )"7L-"BL@"0D)
M8VAA<B!X6S%=.PT**R -"BL@"0D)>&9R;6QE;B ]('-T<GAF<FTH>"P@=F%L
M+" P*3L-"BL@"0E]#0HK("-E;'-E#0H@( D)>&9R;6QE;B ]('-T<GAF<FTH
M3E5,3"P@=F%L+" P*3L-"BL@(V5N9&EF#0H@( D)>&9R;7-T<B ]("AC:&%R
M("HI('!A;&QO8RAX9G)M;&5N("L@,2D[#0H@( D)>&9R;6QE;C(@/2!S=')X
M9G)M*'AF<FUS='(L('9A;"P@>&9R;6QE;B K(#$I.PT*(" )"4%S<V5R="AX
69G)M;&5N,B \/2!X9G)M;&5N*3L-"@``
`
end


Re: Patch for VS.Net 2005's strxfrm() bug

From
Tom Lane
Date:
"William ZHANG" <uniware@zedware.org> writes:
> When I tried to compile pgsql-8.2devel with VS.Net 2005 and do regression
> tests,
> I found the problem. It's a bug inVS.Net 2005:
> http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99694

So why don't you use the fixed version of VS?

            regards, tom lane

Re: [HACKERS] Patch for VS.Net 2005's strxfrm() bug

From
"Hiroshi Saito"
Date:
Hi.

"William ZHANG" <uniware@zedware.org> wrote in message news:ea5fm1$2q6i$1@news.hub.org...
> When I tried to compile pgsql-8.2devel with VS.Net 2005 and do regression
> tests,
> I found the problem. It's a bug inVS.Net 2005:
> http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99694
>

+   /* http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99694 */
+ #if _MSC_VER == 1400
+   {
+    char x[1];
+
+    xfrmlen = strxfrm(x, val, 0);
+   }
+ #else
    xfrmlen = strxfrm(NULL, val, 0);
+ #endif


Hmm, It seems to be the bug of very unpleasant Microsoft.:D
I think that the following is desirable as an evasion measure to add.

#if defined(_MSC_VER) && _MSC_VER == 1400

To be sure, it was only VS2005.

Regards,
Hiroshi Saito


Re: [HACKERS] Patch for VS.Net 2005's strxfrm() bug

From
Andrew Dunstan
Date:
Hiroshi Saito wrote:
> Hmm, It seems to be the bug of very unpleasant Microsoft.:D
> I think that the following is desirable as an evasion measure to add.
>
> #if defined(_MSC_VER) && _MSC_VER == 1400
>
> To be sure, it was only VS2005.
>


Why is this better than:

  #if _MSC_VER == 1400


Surely this will not be true if _MSC_VER is undefined?

cheers

andrew




Re: [HACKERS] Patch for VS.Net 2005's strxfrm() bug

From
"Hiroshi Saito"
Date:
From: "Andrew Dunstan"

> Hiroshi Saito wrote:
> > Hmm, It seems to be the bug of very unpleasant Microsoft.:D
> > I think that the following is desirable as an evasion measure to add.
> >
> > #if defined(_MSC_VER) && _MSC_VER == 1400
> >
> > To be sure, it was only VS2005.
> >
>
>
> Why is this better than:
>
>   #if _MSC_VER == 1400
>
>
> Surely this will not be true if _MSC_VER is undefined?

I experienced injustice and the reason of in OSX for it.

Regards,
Hiroshi Saito


Re: Patch for VS.Net 2005's strxfrm() bug

From
"William ZHANG"
Date:
"Tom Lane" <tgl@sss.pgh.pa.us>
> "William ZHANG" <uniware@zedware.org> writes:
>> When I tried to compile pgsql-8.2devel with VS.Net 2005 and do regression
>> tests,
>> I found the problem. It's a bug inVS.Net 2005:
>> http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99694
>
> So why don't you use the fixed version of VS?

No service pack found for VS.Net 2005 now.

> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>       choose an index scan if your joining column's datatypes do not
>       match
>



Re: [HACKERS] Patch for VS.Net 2005's strxfrm() bug

From
Bruce Momjian
Date:
Hiroshi Saito wrote:
> From: "Andrew Dunstan"
>
> > Hiroshi Saito wrote:
> > > Hmm, It seems to be the bug of very unpleasant Microsoft.:D
> > > I think that the following is desirable as an evasion measure to add.
> > >
> > > #if defined(_MSC_VER) && _MSC_VER == 1400
> > >
> > > To be sure, it was only VS2005.
> > >
> >
> >
> > Why is this better than:
> >
> >   #if _MSC_VER == 1400
> >
> >
> > Surely this will not be true if _MSC_VER is undefined?
>
> I experienced injustice and the reason of in OSX for it.

What was the problem with OSX?  Did it throw a warning of you did an
equality test on an undefined symbol?

--
  Bruce Momjian   bruce@momjian.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

Re: [HACKERS] Patch for VS.Net 2005's strxfrm() bug

From
Bruce Momjian
Date:
Patch attached and applied.  Thanks.

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

Hiroshi Saito wrote:
> Hi.
>
> "William ZHANG" <uniware@zedware.org> wrote in message news:ea5fm1$2q6i$1@news.hub.org...
> > When I tried to compile pgsql-8.2devel with VS.Net 2005 and do regression
> > tests,
> > I found the problem. It's a bug inVS.Net 2005:
> > http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99694
> >
>
> +   /* http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99694 */
> + #if _MSC_VER == 1400
> +   {
> +    char x[1];
> +
> +    xfrmlen = strxfrm(x, val, 0);
> +   }
> + #else
>     xfrmlen = strxfrm(NULL, val, 0);
> + #endif
>
>
> Hmm, It seems to be the bug of very unpleasant Microsoft.:D
> I think that the following is desirable as an evasion measure to add.
>
> #if defined(_MSC_VER) && _MSC_VER == 1400
>
> To be sure, it was only VS2005.
>
> Regards,
> Hiroshi Saito
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings

--
  Bruce Momjian   bruce@momjian.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: src/backend/utils/adt/selfuncs.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v
retrieving revision 1.210
diff -c -c -r1.210 selfuncs.c
*** src/backend/utils/adt/selfuncs.c    24 Jul 2006 01:19:48 -0000    1.210
--- src/backend/utils/adt/selfuncs.c    26 Jul 2006 17:13:26 -0000
***************
*** 2956,2962 ****
           * == as you'd expect.  Can't any of these people program their way
           * out of a paper bag?
           */
!         xfrmlen = strxfrm(NULL, val, 0);
          xfrmstr = (char *) palloc(xfrmlen + 1);
          xfrmlen2 = strxfrm(xfrmstr, val, xfrmlen + 1);
          Assert(xfrmlen2 <= xfrmlen);
--- 2956,2970 ----
           * == as you'd expect.  Can't any of these people program their way
           * out of a paper bag?
           */
! #if _MSC_VER == 1400    /* VS.Net 2005 */
!         /* http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99694 */
!         {
!             char x[1];
!             xfrmlen = strxfrm(x, val, 0);
!         }
! #else
!         xfrmlen = strxfrm(NULL, val, 0);
! #endif
          xfrmstr = (char *) palloc(xfrmlen + 1);
          xfrmlen2 = strxfrm(xfrmstr, val, xfrmlen + 1);
          Assert(xfrmlen2 <= xfrmlen);

Re: [HACKERS] Patch for VS.Net 2005's strxfrm() bug

From
"Florian G. Pflug"
Date:
Bruce Momjian wrote:
>>> Why is this better than:
>>>
>>>   #if _MSC_VER == 1400
>>>
>>>
>>> Surely this will not be true if _MSC_VER is undefined?
>> I experienced injustice and the reason of in OSX for it.
>
> What was the problem with OSX?  Did it throw a warning of you did an
> equality test on an undefined symbol?

The following if evaluated to true on osx, although I'm pretty sure that
_MSC_VER isn't defined on osx ;-)
#if (_MSC_VER < 1300)
...
#endif

replacing it with
#ifdef WIN32
#if (_MSC_VER < 1300)
...
#endif
#endif

fixed the problem.

greetings, Florian Pflug



Re: [HACKERS] Patch for VS.Net 2005's strxfrm() bug

From
andrew@dunslane.net
Date:
> Bruce Momjian wrote:
>>>> Why is this better than:
>>>>
>>>>   #if _MSC_VER == 1400
>>>>
>>>>
>>>> Surely this will not be true if _MSC_VER is undefined?
>>> I experienced injustice and the reason of in OSX for it.
>>
>> What was the problem with OSX?  Did it throw a warning of you did an
>> equality test on an undefined symbol?
>
> The following if evaluated to true on osx, although I'm pretty sure that
> _MSC_VER isn't defined on osx ;-)
> #if (_MSC_VER < 1300)
> ...
> #endif
>
> replacing it with
> #ifdef WIN32
> #if (_MSC_VER < 1300)
> ...
> #endif
> #endif
>
> fixed the problem.
>


No doubt, but that's quite a different test.

cheers

andrew



Re: [HACKERS] Patch for VS.Net 2005's strxfrm() bug

From
"Florian G. Pflug"
Date:
andrew@dunslane.net wrote:
>> Bruce Momjian wrote:
>>>>> Why is this better than:
>>>>>
>>>>>   #if _MSC_VER == 1400
>>>>>
>>>>> Surely this will not be true if _MSC_VER is undefined?
>>>> I experienced injustice and the reason of in OSX for it.
>>> What was the problem with OSX?  Did it throw a warning of you did an
>>> equality test on an undefined symbol?
>> The following if evaluated to true on osx, although I'm pretty sure that
>> _MSC_VER isn't defined on osx ;-)
>> #if (_MSC_VER < 1300)
>> ...
>> #endif
>>
>> replacing it with
>> #ifdef WIN32
>> #if (_MSC_VER < 1300)
>> ...
>> #endif
>> #endif
>>
>> fixed the problem.
>
> No doubt, but that's quite a different test.
I mainly posted this to show what the offending ifdef in pgadmin3 looked like,
since someone referenced it, not as an argument against "#if _MSC_VER = 1400".

I guess "_MSC_VER < 1300" gets interpreted as "0 < 1300" if _MSC_VER is undefined,
so "_MSC_VER = 1400" would actually work.

But it still suprised me a lot that "_MSC_VER < 1300" evaluated to true if _MSC_VER
is undefined - maybe thats the _real_ reason why some people don't like the tri-state
logic in sql - it's because they get confused when trying to use the c preprocessor ;-)

greetings, Florian Pflug


Re: [HACKERS] Patch for VS.Net 2005's strxfrm() bug

From
"Hiroshi Saito"
Date:
From: "Florian G. Pflug"

Ahhhhhhh, It is right.!
I was retracing my memory for what situations the contents were.
I was in distraction.....It seems that it is satisfactory at the reason for ==.

Sorry and Thanks.!!

Regards,
Hiroshi Saito

> Bruce Momjian wrote:
>>>> Why is this better than:
>>>>
>>>>   #if _MSC_VER == 1400
>>>>
>>>>
>>>> Surely this will not be true if _MSC_VER is undefined?
>>> I experienced injustice and the reason of in OSX for it.
>>
>> What was the problem with OSX?  Did it throw a warning of you did an
>> equality test on an undefined symbol?
>
> The following if evaluated to true on osx, although I'm pretty sure that
> _MSC_VER isn't defined on osx ;-)
> #if (_MSC_VER < 1300)
> ...
> #endif
>
> replacing it with
> #ifdef WIN32
> #if (_MSC_VER < 1300)
> ...
> #endif
> #endif
>
> fixed the problem.
>
> greetings, Florian Pflug