Re: strncmp issue
- From: Chuck Swiger <cswiger@xxxxxxx>
- Date: Tue, 28 Apr 2009 10:25:43 -0700
Hi, Channa--
On Apr 28, 2009, at 2:52 AM, Channa wrote:
I am using the freebsd implementation of strncmp for ARM which is an
assembly implementation.
I have a small doubt, when i tested the strncmp by passing the third argument:
'n' as -1 the return values is '0' instead it should '-1'.
When the third argument to strncmp is as below:
ret = strncmp("a","b",-1)
Thanks for the thought, but strncmp() is defined to take a size_t as the third argument, which is unsigned (ie, uint32_t or uint64_t).
Presumably when you tell it to compare with length of -1, that will be converted to UINT_MAX or ULONG_MAX, and strncmp() will run until it finds a null somewhere in one the strings and then return the comparison result. (Or get a segfault, perhaps, if you run off the end into unallocated address space.)
Regards,
--
-Chuck
_______________________________________________
freebsd-current@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscribe@xxxxxxxxxxx"
- References:
- strncmp issue
- From: Channa
- strncmp issue
- Prev by Date: Re: CURRENT+xorg-7.4 on eeePC 900 && X crashes on shutdown
- Next by Date: Re: kern/132715: [lagg] [panic] Panic when creating vlan's on lagg interface
- Previous by thread: Re: strncmp issue
- Next by thread: Re: kern/132715: [lagg] [panic] Panic when creating vlan's on lagg interface
- Index(es):
Relevant Pages
|