RestComm / jss7

RestComm Java SS7 Stack and Services
http://www.restcomm.com/
GNU Affero General Public License v3.0
177 stars 218 forks source link

Wrongly encoded if negative value for longitude #267

Closed nhanth87 closed 6 years ago

nhanth87 commented 6 years ago

From ticket 34763,

map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/mobility/subscriberInformation/GeographicalInformationImpl.java Idea to fix:

public static double decodeLongitude(byte[] data, int begin) { 
int i1 = ((data[begin] & 0xFF) << 16) | ((data[begin + 1] & 0xFF) << 8) | ((data[begin + 2] & 0xFF);

if ((i1 & 0x800000) != 0) { 
i1 = i1 | ((int) 0xFF000000); 
} 

return i1 / koef24; 
}

public static encodeLongitude(byte[] data, double val) { 
int res = (int) (koef24 * val);

if (res > 0x7FFFFF) 
res = 0x7FFFFF;

if (val < 0) 
res |= 0x800000;

data[begin] = (byte) ((res & 0xFF0000) >> 16); 
data[begin + 1] = (byte) ((res & 0xFF00) >> 8); 
data[begin + 2] = (byte) (res & 0xFF); 
}
vetss commented 6 years ago

Fixed by: https://github.com/RestComm/jss7/commit/2543880d6b65343ba6c348a26ac1788e78425d7b