[segyio] 259/376: Reduce scope of variables
Jørgen Kvalsvik
jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:41 UTC 2017
This is an automated email from the git hooks/post-receive script.
jokva-guest pushed a commit to branch debian
in repository segyio.
commit 974514a8ce63621fef937d96ec72e5b0ec7ea89f
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date: Tue Mar 28 13:25:32 2017 +0200
Reduce scope of variables
---
lib/src/segy.c | 12 +++++-------
lib/test/utils.c | 7 ++-----
2 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/lib/src/segy.c b/lib/src/segy.c
index b57bd31..2045fcb 100644
--- a/lib/src/segy.c
+++ b/lib/src/segy.c
@@ -555,12 +555,11 @@ int segy_field_forall( segy_file* fp,
*
* Always read 4 bytes to be sure, there's no significant cost difference.
*/
- size_t readc;
const int zfield = field - 1;
for( int i = start; slicelen > 0; i += step, ++buf, --slicelen ) {
err = segy_seek( fp, i, trace0 + zfield, trace_bsize );
if( err != 0 ) return SEGY_FSEEK_ERROR;
- readc = fread( header + zfield, sizeof( uint32_t ), 1, fp->fp );
+ size_t readc = fread( header + zfield, sizeof( uint32_t ), 1, fp->fp );
if( readc != 1 ) return SEGY_FREAD_ERROR;
segy_get_field( header, field, &f );
@@ -641,7 +640,7 @@ int segy_seek( segy_file* fp,
return SEGY_OK;
}
- int err = SEGY_OK;
+ int err;
#if LONG_MAX == LLONG_MAX
assert( pos <= LONG_MAX );
err = fseek( fp->fp, (long)pos, SEEK_SET );
@@ -651,6 +650,7 @@ int segy_seek( segy_file* fp,
* to LONG_MAX and seek relative to our cursor rather than absolute on file
* begin.
*/
+ err = SEGY_OK;
rewind( fp->fp );
while( pos >= LONG_MAX && err == SEGY_OK ) {
err = fseek( fp->fp, LONG_MAX, SEEK_CUR );
@@ -937,7 +937,6 @@ int segy_offset_indices( segy_file* fp,
int* out,
long trace0,
int trace_bsize ) {
- int err = 0;
int32_t x = 0;
char header[ SEGY_TRACE_HEADER_SIZE ];
@@ -945,7 +944,7 @@ int segy_offset_indices( segy_file* fp,
return SEGY_INVALID_FIELD;
for( int i = 0; i < offsets; ++i ) {
- err = segy_traceheader( fp, i, header, trace0, trace_bsize );
+ const int err = segy_traceheader( fp, i, header, trace0, trace_bsize );
if( err != SEGY_OK ) return err;
segy_get_field( header, offset_field, &x );
@@ -1152,10 +1151,9 @@ static inline int subtr_seek( segy_file* fp,
}
static int reverse( float* arr, int elems ) {
- float tmp;
const int last = elems - 1;
for( int i = 0; i < elems / 2; ++i ) {
- tmp = arr[ i ];
+ const float tmp = arr[ i ];
arr[ i ] = arr[ last - i ];
arr[ last - i ] = tmp;
}
diff --git a/lib/test/utils.c b/lib/test/utils.c
index 9e22125..f1d21a5 100644
--- a/lib/test/utils.c
+++ b/lib/test/utils.c
@@ -72,12 +72,9 @@ static void check(float f1, double * epsm) {
}
static void testIBMFloat() {
- int i;
- float f1;
-
double epsm = 0.0;
- for (i = 0; i < MAX; i++) {
- f1 = rand();
+ for( int i = 0; i < MAX; i++) {
+ const float f1 = rand();
check(f1, &epsm);
check(-f1, &epsm);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/segyio.git
More information about the debian-science-commits
mailing list