invalid argument list of main() return E2BIG
* If invalid number of arguments supplied to main(), return errno E2BIG * add Makefile rule to test memory leak of wrong number of arguments to main() Signed-off-by: Daniel Santos <dacs.git@brilhante.top>
This commit is contained in:
parent
3d304af497
commit
fd66c37285
7
Makefile
7
Makefile
|
@ -61,9 +61,9 @@ clean:
|
|||
run: decimal-to-earth
|
||||
./decimal-to-earth 21
|
||||
|
||||
.PHONY: mem mem1 mem2 mem3
|
||||
.PHONY: mem mem1 mem2 mem3 mem4
|
||||
mem:
|
||||
echo "the memory make rules are: mem1 mem2 mem3"
|
||||
echo "the memory make rules are: mem1 mem2 mem3 mem4"
|
||||
|
||||
mem1: decimal-to-earth
|
||||
valgrind --leak-check=full --show-leak-kinds=all -s decimal-to-earth 999
|
||||
|
@ -74,6 +74,9 @@ mem2: decimal-to-earth
|
|||
mem3: decimal-to-earth
|
||||
valgrind --leak-check=full --show-leak-kinds=all -s decimal-to-earth abc
|
||||
|
||||
mem4: decimal-to-earth
|
||||
valgrind --leak-check=full --show-leak-kinds=all -s decimal-to-earth 2 3
|
||||
|
||||
|
||||
decimal-to-earth_test-1: $(DEP)
|
||||
$(CC) $(CFLAGS) -DFROM_NUMERICALS=\"0123456789\" -DFROM_FIRST_NUMBER_VOID -DFROM_INFINITE_BASE -DTO_NUMERICALS=\"12345\" -o $@ $^
|
||||
|
|
|
@ -545,8 +545,9 @@ numericx_translate(char* from, bool from_units_on_the_end, bool from_first_numbe
|
|||
*
|
||||
* @param argv[] - one number as a string
|
||||
*
|
||||
* @return EXIT_SUCCESS in case of a successful number translation
|
||||
* @return E2BIG in case of wrong number of arguments
|
||||
* @return EXIT_FAILURE in case of unsuccessful number translation
|
||||
* @return EXIT_SUCCESS in case of a successful number translation
|
||||
*/
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
|
@ -555,7 +556,7 @@ main(int argc, char* argv[])
|
|||
if( !(argc == 2) )
|
||||
{
|
||||
fprintf(stderr, "usage: %s <number>\n", PROG_NAME);
|
||||
exit(EXIT_FAILURE);
|
||||
return E2BIG;
|
||||
}
|
||||
|
||||
/* Number variables to be converted */
|
||||
|
|
Loading…
Reference in New Issue