[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 91c204e: Maximum unsigned type numbers as stri
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 91c204e: Maximum unsigned type numbers as string read into larger type |
Date: |
Thu, 27 Dec 2018 12:37:31 -0500 (EST) |
branch: master
commit 91c204ea25e250546155c6271825c3b11e591bca
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Maximum unsigned type numbers as string read into larger type
Until now, when you wanted to select pixels with a label of 255 (for
example on NoiseChisel's output) with Arithmetic, it doesn't select
them. This is because 255 fits into an unsigned 8-bit value, so it is
stored with that type. But being the maximum value, 255 is also the value
used for blank in this type.
With this commit, when the user gives 255 to Arithmetic (and in particular
the library's `gal_type_string_to_number' function), it will be put into
the larger type to avoid such situations. The same fix is implemented for
the 16-bit and 32-bit unsigned types.
---
NEWS | 1 +
lib/type.c | 15 +++++++++++----
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/NEWS b/NEWS
index 30a1673..8ddb577 100644
--- a/NEWS
+++ b/NEWS
@@ -154,6 +154,7 @@ GNU Astronomy Utilities NEWS -*-
outline -*-
bug #55079: Blank EPS or PDF page when width options not given.
bug #55157: No sanity check on values given to Crop's --section.
bug #55295: Crash when more than one collapse operator called.
+ bug #55298: Arithmetic reading 255 on command-line as blank.
diff --git a/lib/type.c b/lib/type.c
index 5d89a72..5a42e84 100644
--- a/lib/type.c
+++ b/lib/type.c
@@ -568,10 +568,17 @@ gal_type_string_to_number(char *string, uint8_t *type)
}
else
{
- if (d<=UINT8_MAX) { u8=d; ptr=&u8; *type=GAL_TYPE_UINT8; }
- else if(d<=UINT16_MAX) { u16=d; ptr=&u16; *type=GAL_TYPE_UINT16; }
- else if(d<=UINT32_MAX) { u32=d; ptr=&u32; *type=GAL_TYPE_UINT32; }
- else { u64=d; ptr=&u64; *type=GAL_TYPE_UINT64; }
+ /* Note that the blank values are set to the maximum values in
+ unsigned types. A blank value should be given as a blank
+ string to this function (`GAL_BLANK_STRING'). So, to avoid
+ confusing situations (for example when the user gives 255), if
+ the value is equal to the given maximum of the given type,
+ we'll assign it to a larger type. In other words, we won't be
+ using the `<=MAX', but `<MAX'. */
+ if (d<UINT8_MAX) { u8=d; ptr=&u8; *type=GAL_TYPE_UINT8; }
+ else if(d<UINT16_MAX) { u16=d; ptr=&u16; *type=GAL_TYPE_UINT16; }
+ else if(d<UINT32_MAX) { u32=d; ptr=&u32; *type=GAL_TYPE_UINT32; }
+ else { u64=d; ptr=&u64; *type=GAL_TYPE_UINT64; }
}
}
else
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master 91c204e: Maximum unsigned type numbers as string read into larger type,
Mohammad Akhlaghi <=