feat(#19647): check longitude and latitude max value

This commit is contained in:
marmonier_c 2024-02-19 12:56:22 +01:00 committed by AndersBroman
parent 5e9e75537a
commit f501c57fc3
1 changed files with 19 additions and 9 deletions

View File

@ -1446,6 +1446,8 @@ get_latitude_or_longitude(gchar *buf, int option, guint64 unmasked_value)
*/
const guint variableBitSize = 34;
const guint fractionnalBitSize = 25;
const guint64 maxlatitude = (G_GINT64_CONSTANT(0x1) << fractionnalBitSize) * G_GINT64_CONSTANT(90); // 90 degrees
const guint64 maxlongitude = (G_GINT64_CONSTANT(0x1) << fractionnalBitSize) * G_GINT64_CONSTANT(180); // 180 degrees
guint64 masked_value = getUint64MaskedValue(unmasked_value, variableBitSize); // get 34-bit value
@ -1462,6 +1464,7 @@ get_latitude_or_longitude(gchar *buf, int option, guint64 unmasked_value)
guint64 fixedSizeDecimal = convertFractionalToFixedSizeDecimal(absolute_value, fractionnalBitSize, numberOfDigitToDisplay);
const char *direction;
const char *err_str = "";
if (option == 0){
// Latitude - north/south directions
if (isNegative){
@ -1469,6 +1472,9 @@ get_latitude_or_longitude(gchar *buf, int option, guint64 unmasked_value)
} else {
direction = "North";
}
if(absolute_value > maxlatitude){
err_str = "[Error: value > 90 degrees] ";
}
} else {
// Longitude - east/west directions
if (isNegative){
@ -1476,13 +1482,17 @@ get_latitude_or_longitude(gchar *buf, int option, guint64 unmasked_value)
} else {
direction = "East";
}
if(absolute_value > maxlongitude){
err_str = "[Error: value > 180 degrees] ";
}
}
const guint64 fractionalMask = (G_GINT64_CONSTANT(0x1) << fractionnalBitSize) - 1;
// %04 correspond to numberOfDigitToDisplay
snprintf(buf, ITEM_LABEL_LENGTH, "%u.%04" PRIu64 " degrees %s (0x%010" PRIX64 " - %u-bit integer part 0x%04" PRIX64 " / %u-bit fractional part 0x%08" PRIX64 ")",
integerPortion, fixedSizeDecimal, direction, masked_value,
snprintf(buf, ITEM_LABEL_LENGTH, "%s%u.%04" PRIu64 " degrees %s (0x%010" PRIX64 " - %u-bit integer part 0x%04" PRIX64 " / %u-bit fractional part 0x%08" PRIX64 ")",
err_str,
integerPortion, fixedSizeDecimal, direction, masked_value,
variableBitSize - fractionnalBitSize, masked_value >> fractionnalBitSize,
fractionnalBitSize, masked_value & fractionalMask
);
@ -1502,7 +1512,7 @@ static void
altitude_base(gchar *buf, guint32 unmasked_value) {
// RFC6225
// Altitude: A 30-bit value defined by the AType field.
// In some cases, the altitude of the location might not be provided.
// In some cases, the altitude of the location might not be provided.
// An Altitude Type value of zero indicates that the altitude is not
// given to the client. In this case, the Altitude and Altitude
// Uncertainty fields can contain any value and MUST be ignored.