Re: kdp_match_name
Re: kdp_match_name
- Subject: Re: kdp_match_name
- From: Stan Sieler <email@hidden>
- Date: Thu, 17 Sep 2015 15:23:53 -0700
Not a answer for you, but, re:
> […] strncmp(kdpname, "serial", sizeof(kdpname)) != 0)
That struck me as odd. Wouldn’t ’6’ be much better than sizeof(kdpname)?
(Or, wouldn’t using ’strcmp’ be much better here?)
After all, if ’kdpname’ happens to be a pointer (not an array), then the size of it
could be 4 or 8 … and 4 is too short (allowing “serious” to match :)
(Thus, it would be a bug.)
Alternatively, if kdpname is an array of 7 or more bytes, why bother with the ’n’ of strncmp,
since we know the comparison will stop after loading the 7th byte, worst case (thus, no ’n’ needed
to limit the loop).
If kdpname is an array of 6 or less bytes, then 'strcmp (kdpname, “serial”)’ would give
the compiler a chance to say “hey, that will never match”, but the ’strncmp’ wouldn’t
provide that opportunity.
This looks like a great candidate for a simple “strcmp”.
I’m asking partially to learn if my understanding of when to use
strncmp is wrong or not.
(I’m not interested in the performance difference here … yeah, the strncmp is slower,
but by such a small amount that the savings earned (across all future runs) by recoding
is more than lost by the cost of the time to read this sentence :)
thanks,
Stan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden