Skip to content

Commit 37a803c

Browse files
committed
Fix swapping key numeric values on Big Endian machines.
Swap the key length when WORDS_BIGENDIAN is defined Make the IOFF structure depending on WORDS_BIGENDIAN modified: storage/connect/connect.cc modified: storage/connect/xindex.h
1 parent 65ed254 commit 37a803c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

storage/connect/connect.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,12 @@ RCODE CntIndexRead(PGLOBAL g, PTDB ptdb, OPVAL op,
801801

802802
if (!valp->IsTypeNum()) {
803803
if (colp->GetColUse(U_VAR)) {
804+
#if defined(WORDS_BIGENDIAN)
805+
((char*)&lg)[0]= ((char*)kp)[1];
806+
((char*)&lg)[1]= ((char*)kp)[0];
807+
#else // !WORDS_BIGENDIAN
804808
lg= *(short*)kp;
809+
#endif //!WORDS_BIGENDIAN
805810
kp+= sizeof(short);
806811
rcb= valp->SetValue_char(kp, (int)lg);
807812
} else
@@ -919,7 +924,12 @@ int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len,
919924

920925
if (!valp->IsTypeNum()) {
921926
if (colp->GetColUse(U_VAR)) {
927+
#if defined(WORDS_BIGENDIAN)
928+
((char*)&lg)[0]= ((char*)kp)[1];
929+
((char*)&lg)[1]= ((char*)kp)[0];
930+
#else // !WORDS_BIGENDIAN
922931
lg= *(short*)p;
932+
#endif //!WORDS_BIGENDIAN
923933
p+= sizeof(short);
924934
rcb= valp->SetValue_char((char*)p, (int)lg);
925935
} else

storage/connect/xindex.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ typedef struct index_def : public BLOCK {
6565

6666
typedef struct index_off {
6767
union {
68+
#if defined(WORDS_BIGENDIAN)
69+
struct {int High; int Low;};
70+
#else // !WORDS_BIGENDIAN
6871
struct {int Low; int High;};
72+
#endif //!WORDS_BIGENDIAN
6973
longlong Val; // File position
7074
}; // end of union
7175
} IOFF;

0 commit comments

Comments
 (0)