Fix yaml parser error when meets .nan (refactor on #754) (#781) (#785)

* Fix yaml parser error when meets .nan

Signed-off-by: Ada-King <Bingtao.Du@sony.com>

Correct code style

Signed-off-by: Ada-King <Bingtao.Du@sony.com>

Modify as suggested

Signed-off-by: Ada-King <Bingtao.Du@sony.com>

Improve test

Signed-off-by: Ada-King <Bingtao.Du@sony.com>

Fix minor flaw

Signed-off-by: Ada-King <Bingtao.Du@sony.com>

Fix minor flaw again

Signed-off-by: Ada-King <Bingtao.Du@sony.com>

Satisfy windows CI

Signed-off-by: Ada-King <Bingtao.Du@sony.com>

Change the match rule for special float

Signed-off-by: Ada-King <Bingtao.Du@sony.com>

Distinguish +.inf and -.inf

Signed-off-by: Ada-King <Bingtao.Du@sony.com>

* Remove unnecessary #include change.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* Add in two more necessary includes.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

Co-authored-by: Ada-King <Bingtao.Du@sony.com>
Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
Signed-off-by: Stephen Brawner <brawner@gmail.com>

Co-authored-by: Ada-King <Bingtao.Du@sony.com>
Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
This commit is contained in:
brawner 2020-10-05 18:12:26 -07:00 committed by GitHub
parent 2c513aa0ed
commit 7c1f2746f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 2 deletions

View file

@ -12,7 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "rcutils/allocator.h"
#include "rcutils/error_handling.h"
@ -117,7 +120,30 @@ void * get_value(
{
errno = 0;
endptr = NULL;
dval = strtod(value, &endptr);
const char * iter_ptr = NULL;
if ((0 == strcmp(value, ".nan")) ||
(0 == strcmp(value, ".NaN")) ||
(0 == strcmp(value, ".NAN")) ||
(0 == strcmp(value, ".inf")) ||
(0 == strcmp(value, ".Inf")) ||
(0 == strcmp(value, ".INF")) ||
(0 == strcmp(value, "+.inf")) ||
(0 == strcmp(value, "+.Inf")) ||
(0 == strcmp(value, "+.INF")) ||
(0 == strcmp(value, "-.inf")) ||
(0 == strcmp(value, "-.Inf")) ||
(0 == strcmp(value, "-.INF")))
{
for (iter_ptr = value; !isalpha(*iter_ptr); ) {
iter_ptr += 1;
}
dval = strtod(iter_ptr, &endptr);
if (*value == '-') {
dval = -dval;
}
} else {
dval = strtod(value, &endptr);
}
if ((0 == errno) && (NULL != endptr)) {
if ((NULL != endptr) && (endptr != value)) {
if (('\0' != *value) && ('\0' == *endptr)) {