bibutils\fields.c: In function 'fields_findv_each_add':
C:\hs-bibutils\bibutils\fields.c:459:7: error:
warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
v = ( void * )( (long) n );
This looks fishy. The n variable is int and that is only 32 bits wide on Windows. If any pointer gets transported through the integer it will be truncated in v variable.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It actually is fine, though apparently the cast should be ( long long ) under Windows, rather than ( long ), and the ( long long ) cast also works under Linux; long long is 64 bit under both architectures. This should silence the warning.
fields_findv_each() will put pointers to str, pointers to char (C-style strings), or indicies of hits into the output void pointer list (vplist), depending on the mode that the user has chosen. In the case of storing indicies in the vplist, I'm abusing the cast system to cast the index n into a void pointer so there's a uniform output mechanism. No real pointer ever passes through n, which as you point out would cause truncation and bad things.
To extract the integer values, the code would have to look something like:
fields *f;
vplist hits;
vplist_init( &hits );
status = fields_findv_each( f, LEVEL_ANY, FIELDS_POSP_FLAG, &hits, "AUTHOR" );
if ( status==FIELDS_OK ) {
for ( i=0; i<hits.n; ++i ) {
n = ( int ) vplist_get( &hits, i );
/* ... */
}
}
I don't believe anything in bibutils uses FIELDS_POSP_FLAG, but I have other code that does.
Thanks for the report, particularly for Windows compilers that I don't have access to.
Chris.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am getting the follwing warning in hs-bibutils compilation on 64 bit Windows:
This looks fishy. The
n
variable isint
and that is only 32 bits wide on Windows. If any pointer gets transported through the integer it will be truncated inv
variable.It actually is fine, though apparently the cast should be ( long long ) under Windows, rather than ( long ), and the ( long long ) cast also works under Linux; long long is 64 bit under both architectures. This should silence the warning.
fields_findv_each() will put pointers to str, pointers to char (C-style strings), or indicies of hits into the output void pointer list (vplist), depending on the mode that the user has chosen. In the case of storing indicies in the vplist, I'm abusing the cast system to cast the index n into a void pointer so there's a uniform output mechanism. No real pointer ever passes through n, which as you point out would cause truncation and bad things.
To extract the integer values, the code would have to look something like:
I don't believe anything in bibutils uses FIELDS_POSP_FLAG, but I have other code that does.
Thanks for the report, particularly for Windows compilers that I don't have access to.
Chris.
This is now updated in version 6.7