[Delphi 2009 BUG] StrToIntDef('丸', 0) = 8
来源:互联网 发布:java高级编程 编辑:程序博客网 时间:2024/06/12 01:10
如果你StrToIntDef('丸子', 0),必然返回0,而一个字符的‘丸’,却返回8。
跟踪之后,发现竟然用这样的代码去处理UniCode字符串,而‘丸’的UniCode编码是 $38 $4E,很搞笑吧。
System.Pas Line 7532,完整代码如下:
跟踪之后,发现竟然用这样的代码去处理UniCode字符串,而‘丸’的UniCode编码是 $38 $4E,很搞笑吧。
- MOV BL,[ESI]
- {$IFNDEF UNICODE}
- INC ESI
- {$ELSE}
- ADD ESI, 2
- {$ENDIF}
- CMP BL,' '
- JE @@blankLoop
- function _ValLong(const s: string; var code: Integer): Longint;
- {$IFDEF PUREPASCAL}
- var
- I, Len: Integer;
- Negative, Hex: Boolean;
- begin
- // U-OK
- I := 1;
- code := -1;
- Result := 0;
- Negative := False;
- Hex := False;
- Len := Length(s);
- while (I <= Len) and (s[I] = ' ') do Inc(I);
- if I > Len then Exit;
- case s[I] of
- '$',
- 'x',
- 'X': begin
- Hex := True;
- Inc(I);
- end;
- '0': begin
- Hex := (Len > I) and (UpCase(s[I+1]) = 'X');
- if Hex then Inc(I,2);
- end;
- '-': begin
- Negative := True;
- Inc(I);
- end;
- '+': Inc(I);
- end;
- if Hex then
- while I <= Len do
- begin
- if Result > (High(Result) div 16) then
- begin
- code := I;
- Exit;
- end;
- case s[I] of
- '0'..'9': Result := Result * 16 + Ord(s[I]) - Ord('0');
- 'a'..'f': Result := Result * 16 + Ord(s[I]) - Ord('a') + 10;
- 'A'..'F': Result := Result * 16 + Ord(s[I]) - Ord('A') + 10;
- else
- code := I;
- Exit;
- end;
- end
- else
- while I <= Len do
- begin
- if Result > (High(Result) div 10) then
- begin
- code := I;
- Exit;
- end;
- Result := Result * 10 + Ord(s[I]) - Ord('0');
- Inc(I);
- end;
- if Negative then
- Result := -Result;
- code := 0;
- end;
- {$ELSE}
- asm
- { FUNCTION _ValLong( s: string; VAR code: Integer ) : Longint; }
- { ->EAX Pointer to string }
- { EDX Pointer to code result }
- { <-EAX Result }
- PUSH EBX
- PUSH ESI
- PUSH EDI
- MOV ESI,EAX
- PUSH EAX { save for the error case }
- TEST EAX,EAX
- JE @@empty
- XOR EAX,EAX
- XOR EBX,EBX
- MOV EDI,07FFFFFFFH / 10 { limit }
- @@blankLoop:
- MOV BL,[ESI]
- {$IFNDEF UNICODE}
- INC ESI
- {$ELSE}
- ADD ESI, 2
- {$ENDIF}
- CMP BL,' '
- JE @@blankLoop
- @@endBlanks:
- MOV CH,0
- CMP BL,'-'
- JE @@minus
- CMP BL,'+'
- JE @@plus
- @@checkDollar:
- CMP BL,'$'
- JE @@dollar
- CMP BL, 'x'
- JE @@dollar
- CMP BL, 'X'
- JE @@dollar
- CMP BL, '0'
- JNE @@firstDigit
- MOV BL, [ESI]
- {$IFNDEF UNICODE}
- INC ESI
- {$ELSE}
- ADD ESI, 2
- {$ENDIF}
- CMP BL, 'x'
- JE @@dollar
- CMP BL, 'X'
- JE @@dollar
- TEST BL, BL
- JE @@endDigits
- JMP @@digLoop
- @@firstDigit:
- TEST BL,BL
- JE @@error
- @@digLoop:
- SUB BL,'0'
- CMP BL,9
- JA @@error
- CMP EAX,EDI { value > limit ? }
- JA @@overFlow
- LEA EAX,[EAX+EAX*4]
- ADD EAX,EAX
- ADD EAX,EBX { fortunately, we can't have a carry }
- MOV BL,[ESI]
- {$IFNDEF UNICODE}
- INC ESI
- {$ELSE}
- ADD ESI, 2
- {$ENDIF}
- TEST BL,BL
- JNE @@digLoop
- @@endDigits:
- DEC CH
- JE @@negate
- TEST EAX,EAX
- JGE @@successExit
- JMP @@overFlow
- @@empty:
- {$IFNDEF UNICODE}
- INC ESI
- {$ELSE}
- ADD ESI, 2
- {$ENDIF}
- JMP @@error
- @@negate:
- NEG EAX
- JLE @@successExit
- JS @@successExit { to handle 2**31 correctly, where the negate overflows }
- @@error:
- @@overFlow:
- POP EBX
- SUB ESI,EBX
- JMP @@exit
- @@minus:
- INC CH
- @@plus:
- MOV BL,[ESI]
- {$IFNDEF UNICODE}
- INC ESI
- {$ELSE}
- ADD ESI, 2
- {$ENDIF}
- JMP @@checkDollar
- @@dollar:
- MOV EDI,0FFFFFFFH
- MOV BL,[ESI]
- {$IFNDEF UNICODE}
- INC ESI
- {$ELSE}
- ADD ESI, 2
- {$ENDIF}
- TEST BL,BL
- JZ @@empty
- @@hDigLoop:
- CMP BL,'a'
- JB @@upper
- SUB BL,'a' - 'A'
- @@upper:
- SUB BL,'0'
- CMP BL,9
- JBE @@digOk
- SUB BL,'A' - '0'
- CMP BL,5
- JA @@error
- ADD BL,10
- @@digOk:
- CMP EAX,EDI
- JA @@overFlow
- SHL EAX,4
- ADD EAX,EBX
- MOV BL,[ESI]
- {$IFNDEF UNICODE}
- INC ESI
- {$ELSE}
- ADD ESI, 2
- {$ENDIF}
- TEST BL,BL
- JNE @@hDigLoop
- DEC CH
- JNE @@successExit
- NEG EAX
- @@successExit:
- POP ECX { saved copy of string pointer }
- XOR ESI,ESI { signal no error to caller }
- @@exit:
- {$IFDEF UNICODE}
- SHR ESI, 1
- {$ENDIF}
- MOV [EDX],ESI
- POP EDI
- POP ESI
- POP EBX
- end;
- {$ENDIF}
- [Delphi 2009 BUG] StrToIntDef('丸', 0) = 8
- Delphi的StrToIntDef函数
- StrToIntDef
- Delphi的bug
- Delphi的一些Bug
- delphi 常见bug
- StrToIntDef - 函数功能及说明
- 关于Borland Delphi's Bug~~
- 关于Borland Delphi's Bug~~
- delphi Ado的一个bug
- DELPHI中BUG修改备忘
- delphi xe2 listview viewstyle bug
- Delphi 7内存管理bug
- 发现 Delphi 2009 VCL 源码中一处可能导致死循环的 Bug
- Delphi 6 SOAP 源码中的BUG修正
- 发现Delphi 2005的几个小Bug
- 再谈Delphi中关于“四舍五入的BUG”
- Delphi 2005 update_3 还有bug没改
- String 截去其中的一段
- 迅驰时尚盛典,跟明星近距离接触!
- OA项目总结 ssh 框架学习总结(一)
- 窗体的几个属性.
- jsp写xml文件 经典实例
- [Delphi 2009 BUG] StrToIntDef('丸', 0) = 8
- 很简单的要求,但试了好几种方法,最后才写出来
- 分数延迟的计算和仿真都做出来了
- 给想做C/C++程序员毕业生的一些建议(一)
- 大市场哦.
- 在.net中使用jmail发送Email(部分代码)
- 编写windows程序要记住的结构体
- Java HTMLEncode & HTMLDecode
- Oracle中SQL语句执行效率问题的查找与解决