[Bug libc/17111] New: STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main ()
sergey.churayev.76 at gmail dot com
sourceware-bugzilla@sourceware.org
Thu Jul 3 21:45:00 GMT 2014
https://sourceware.org/bugzilla/show_bug.cgi?id=17111
Bug ID: 17111
Summary: STRTOL(3) unexpected behavior when use '`' before
number (i.e."```1") as argument of main ()
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: libc
Assignee: unassigned at sourceware dot org
Reporter: sergey.churayev.76 at gmail dot com
CC: drepper.fsp at gmail dot com
Hi,
This is Linux Programmer's Manual STRTOL(3) here:
http://man7.org/linux/man-pages/man3/strtol.3.html
--------------------------------------------------------------------
Program source
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
#include <errno.h>
int
main(int argc, char *argv[])
{
int base;
char *endptr, *str;
long val;
if (argc < 2) {
fprintf(stderr, "Usage: %s str [base]\n", argv[0]);
exit(EXIT_FAILURE);
}
str = argv[1];
base = (argc > 2) ? atoi(argv[2]) : 10;
errno = 0; /* To distinguish success/failure after call */
val = strtol(str, &endptr, base);
/* Check for various possible errors */
if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
|| (errno != 0 && val == 0)) {
perror("strtol");
exit(EXIT_FAILURE);
}
if (endptr == str) {
fprintf(stderr, "No digits were found\n");
exit(EXIT_FAILURE);
}
/* If we got here, strtol() successfully parsed a number */
printf("strtol() returned %ld\n", val);
if (*endptr != '\0') /* Not necessarily an error... */
printf("Further characters after number: %s\n", endptr);
exit(EXIT_SUCCESS);
}
--------------------------------------------------------------------
I use name "strtol_test" to run and use "`````1" as argument of main.
I see next problem:
%% strtol_test ````1
Segmentation fault
Segmentation fault
No digits were found
%%
Any ideas?
Best regards,
Serg.
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the Glibc-bugs
mailing list