ideawu / Objective-C-RSA

Doing RSA encryption and decryption with Objective-C on iOS
http://www.ideawu.com/blog/post/132.html
Other
1.15k stars 280 forks source link

fixed type warnings #31

Closed Chorsfield closed 7 years ago

Chorsfield commented 7 years ago

I am a little unsure about the changes made on lines 325-327. The code is checking to see if a unsigned int is less than 0 which will never happen. There has to be a better way of doing the without losing precision or causing a warning in everyone who uses this lib's project.

ideawu commented 7 years ago

int is RIGHT. NSUInteger is WRONG.

Why would you change it from int to NSUInteger?

Chorsfield commented 7 years ago

outlen is of type size_t which is an unsigned long. Comparing an int to an unsigned long is WRONG. It causes warnings to appear in everybody's project that uses your code.

ideawu commented 7 years ago

What the FUCK is this?

NSUInteger idxFirstZero = -1;
...
if ( idxFirstZero < 0 ) {

Have you ever learnt real programming basic?

Why the fuck to fix a warning with an error? If you want to fix the compile warning, just fix the compile warning itself, not others.

Just make a type casting:

for ( int i = 0; i < (int)outlen; i++ )
ideawu commented 7 years ago
            int idxFirstZero = -1;
            int idxNextZero = (int)outlen;
            for ( int i = 0; i < outlen; i++ ) {

The compile warning is

for ( int i = 0; i < outlen; i++ ) {

Why the heck made a modification to

NSUInteger idxFirstZero = -1;
NSUInteger idxNextZero = outlen;
ideawu commented 7 years ago

You can fix the compile warning by

for ( int i = 0; i < (int)outlen; i++ )

or

for ( NSUInteger i = 0; i < outlen; i++ ) {

The second is what you made. But why edit

int idxFirstZero = -1;
int idxNextZero = (int)outlen;

to

NSUInteger idxFirstZero = -1;
NSUInteger idxNextZero = outlen;
ideawu commented 7 years ago

Yes, if i is uint, idxFirstZero = i; will cause compile warning, just fix it.

Chorsfield commented 7 years ago

The bug is in YOUR code and everyone who uses YOUR code. I did fix it in YOUR code and like I pointed out in my original PR I wasn't sure about the very lines of code you are complaining about. But seeing as you are now aware of the bug you can obviously fix it in YOUR code.

ideawu commented 7 years ago

不懂就要虚心地学.