Skip to content

AlgoMarker Numeric verification #17

@alonyado

Description

@alonyado

When the input request contains string like "130s", c++ stof extract 130 out of this string.
The intended behavior, should be strict.

This effect only AlgoMarker API.

If we want to solve, we can edit the code in SerializableObject.h for med_stof, med_stoi, med_stoll:

inline float med_stof(const string &_Str)
{
	try
	{
		return stof(_Str);
	}
	catch (exception &e)
	{
		HMTHROW_AND_ERR("invalid stof argument [%s]\n", _Str.c_str());
	}
}

to be:

inline float med_stof(const string &_Str)
{
	try
	{
		size_t pos;
		float res;
		res = stof(_Str, &pos);
		if (pos < _Str.size())
			MTHROW_AND_ERR("invalid stof argument [%s]\n", _Str.c_str());

		return res;
	}
	catch (exception &e)
	{
		HMTHROW_AND_ERR("invalid stof argument [%s]\n", _Str.c_str());
	}
}

This will make sure all the string is being parsed as numeric.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions