lkml.org 
[lkml]   [2013]   [Oct]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [tpmdd-devel] [PATCH 1/2] tpm/tpm_ppi: Do not compare strcmp(a, b) == -1
On Wed, Oct 30, 2013 at 01:40:27AM +0100, Peter Huewe wrote:
> strcmp does return the difference between two strings not only -1,0,1
> consequently
> if (strcmp (a,b) == -1)
> might lead to taking the wrong branch
>
> -> compare with <= instead.

I've always thought this was the preferred idiom:

cmp(a,b) == 0
cmp(a,b) < 0
cmp(a,b) > 0

As the operator matches what is actually happening in all cases.

'>= -1' doesn't mean a >= b.

Regards,
Jason


\
 
 \ /
  Last update: 2013-10-30 18:01    [W:0.091 / U:0.252 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site