Skip to content

Commit c0efef6

Browse files
committed
fixup! Switch to FieldData set_field
1 parent 93aa6fc commit c0efef6

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Diff for: lib/src/segy.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -689,27 +689,28 @@ static int set_field( char* header,
689689
const field_data* fd ) {
690690

691691
field_data w_fd = {.buffer = fd->buffer, .type = table[ field ]};
692+
uint8_t * buf8 = (uint8_t*)&w_fd.buffer;
693+
uint16_t* buf16 = (uint16_t*)&w_fd.buffer;
694+
uint32_t* buf32 = (uint32_t*)&w_fd.buffer;
692695

693696
switch ( w_fd.type ) {
694697

695698
case SEGY_SIGNED_INTEGER_4_BYTE:
696-
w_fd.buffer = htobe32( (int32_t)w_fd.buffer );
697-
memcpy( header + (field - 1), &(w_fd.buffer), formatsize( w_fd.type ));
699+
case SEGY_UNSIGNED_INTEGER_4_BYTE:
700+
*buf32 = htobe32( *buf32 );
701+
memcpy( header + (field - 1), buf32, formatsize( w_fd.type ));
698702
return SEGY_OK;
699703

700704
case SEGY_SIGNED_SHORT_2_BYTE:
701-
w_fd.buffer = htobe16( (int16_t)w_fd.buffer );
702-
memcpy( header + (field - 1), &(w_fd.buffer), formatsize( w_fd.type ));
703-
return SEGY_OK;
704-
705705
case SEGY_UNSIGNED_SHORT_2_BYTE:
706-
w_fd.buffer = htobe16( (uint16_t)w_fd.buffer );
707-
memcpy( header + (field - 1), &(w_fd.buffer), formatsize( w_fd.type ));
706+
*buf16 = htobe16( *buf16 );
707+
memcpy( header + (field - 1), buf16, formatsize( w_fd.type ));
708708
return SEGY_OK;
709709

710710
case SEGY_UNSIGNED_CHAR_1_BYTE:
711-
w_fd.buffer = (uint8_t) w_fd.buffer;
712-
memcpy( header + (field - 1), &(w_fd.buffer), formatsize( w_fd.type ));
711+
case SEGY_SIGNED_CHAR_1_BYTE:
712+
*buf8 = (uint8_t) *buf8;
713+
memcpy( header + (field - 1), buf8, formatsize( w_fd.type ));
713714
return SEGY_OK;
714715

715716
default:

0 commit comments

Comments
 (0)