Ethereal-dev: [Ethereal-dev] lemon.c strlen wrong type

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: stephen samuel <samuel@xxxxxxxxxxx>
Date: Tue, 26 Jun 2001 05:29:28 -0700
When I compiled ethereal under Redhat Linux 7.0, I got a complaint
about the type returned by an expression on a call to printf.
It was complaining that the expression was not of type 'int',
although it was being used a a length parameter to printf.

The problem appears to be that strlen is of type size_t.
there is no guarantee that size_t is going to be of type 
int (that's why it is typedeffed). Unfortunately, the whole
expression inherits the type of size_t, and this causes the
printf call to complain.

(there are other places where strlen is used, but they are 
automatically cast down to the proper type.  When doing a 
subroutine call, however, the type needed is (in theory).
not really known.).

The solution I came up with was to cast the return value of
strlen at the needed locations (and hope for no overflow!).


context diffs are included

28c28
< ** $Id: lemon.c,v 1.1 2001/06/26 12:11:26 samuel Exp $
---
> ** $Id: lemon.c,v 1.10 2001/06/26 12:19:27 samuel Exp samuel $
1699c1699
<           max-strlen(op[i].label)-9,"",op[i].message);
---
>           max-(int)strlen(op[i].label)-9,"",op[i].message);
1704c1704
<           max-strlen(op[i].label)-6,"",op[i].message);
---
>           (int)max-(int)strlen(op[i].label)-6,"",op[i].message);
1709c1709
<           max-strlen(op[i].label)-8,"",op[i].message);
---
>           (int)max-(int)strlen(op[i].label)-8,"",op[i].message);
-- 
Stephen Samuel +1(604)876-0426                     samuel@xxxxxxxxxxx
I finally understood that the derogatory term "Indian giver" referred,
not to the Indians themselves, but, rather, to our treatment of them.