Bug? Integer comparison of iOS programs packaged by air

Source: Internet
Author: User

I found a Flash Player crash bug when executing netstream. Play. I did not expect to encounter another air bug today.

Different from the previous bug, this bug is quite easy to reproduce, but I still found a reproduction Method for one day.

Problem Reproduction ? View
Code ActionScript

12345678910111213141516171819202122232425262728293031323334353637383940414243
Package {import flash. display. Sprite; import flash. filesystem. file; import flash. Text. textfield;/*** Test the problem that the unit and INT In the IOS distribution package cannot be compared */PublicClassIosuinttest extends sprite {publicFunctionIosuinttest () {super (); Init (); showinfo (-1 <= zero_int); showinfo (-1 <= zero_uint); showinfo (_ num <= zero_int ); showinfo (_ num <= zero_uint);} privateVaR_ TF: textfield; privateVaR_ Num: Int =-1; public static const zero_int: Int = 0; public static const zero_uint: uint = 0; privateFunctionInit (): void {_ TF =NewTextfield (); _ TF. width = 400; _ TF. Height = 400; this. addchild (_ TF);} privateFunctionShowinfo ($ info: *): void {_ TF. appendtext (string ($ info) + file. lineending );}}}

Everyone knows that the values of the four comparison expressions in showinfo should be true. Well, yes, in the debugging version IPA (target IPA-Debug), their values are true.

However, in the IPA used for publishing, their values are not all true!

I am talking about the "IPA for release" here. If Adobe is used, it is "temporary packages restricted for distribution" and "final release packages deployed to the Apple App Store ".

Install this package on iOS devices. The four values are true, false, true, and false.

Problem Analysis

The problem lies in the comparison between int and uint. Because air is packaged into IPA, the air program is directly packaged into a binary code, rather than a virtual machine (APK is in this form ). Therefore, IPA created using air is theoretically no different from IPA written using objective-C. This is why the IPA written by air can be used in the app store. Otherwise, it's strange that Adobe is not stuck in Apple's dictatorship!

Since it is an objective-C code, the type conversion rules of objective-C also apply to this comparison expression. In objective-C, when int-1 and uint 0 are compared to each other,-1 is converted to uint to get 4294967294, (4294967294 <= 0) the value must be false.

Objective-C is based on the C language. In the C language, this is called integral promotion ).

The following is an excerpt from the C programming language.

A character, a short integer, or an integer bit-field, all either signed or not, or an object of Enumeration type, may be used in an expression wherever an integer maybe used. if an int can represent all the values of the original type, then the value is converted
To int; otherwise the value is converted to unsigned Int. This process is called integral promotion.

In ActionScript, int and uint types are not upgraded. Both int and uint are based on number. In AVM, it may be the same thing.

From this point of view, this is not a bug, but a feature of different languages. However, since Adobe is vigorously promoting the development of IOS applications for air, it is necessary to consider the differences between different languages to avoid such mistakes that are easily overlooked.

This bug is simple to say, but it is still very difficult to find such a small error in an existing large project. I have been looking for a whole day!

The difficulty lies in that the rapid release of the target IPA-Debug file does not cause integer upgrades. This leads to normal programs during debugging and abnormal programs during release. This is definitely Adobe's mistake.

To locate the problem, I had to write a debug information panel that is displayed in the project and continuously package it to test the values of expressions at different positions in the project. It takes 20 minutes to package each time! This is crazy.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.