OpenCoverage

strtonum.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssh/src/openbsd-compat/strtonum.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* $OpenBSD: strtonum.c,v 1.6 2004/08/03 19:38:01 millert Exp $ */-
2-
3/*-
4 * Copyright (c) 2004 Ted Unangst and Todd Miller-
5 * All rights reserved.-
6 *-
7 * Permission to use, copy, modify, and distribute this software for any-
8 * purpose with or without fee is hereby granted, provided that the above-
9 * copyright notice and this permission notice appear in all copies.-
10 *-
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES-
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF-
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR-
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES-
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN-
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF-
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.-
18 */-
19-
20/* OPENBSD ORIGINAL: lib/libc/stdlib/strtonum.c */-
21-
22#include "includes.h"-
23-
24#ifndef HAVE_STRTONUM-
25#include <stdlib.h>-
26#include <limits.h>-
27#include <errno.h>-
28-
29#define INVALID 1-
30#define TOOSMALL 2-
31#define TOOLARGE 3-
32-
33long long-
34strtonum(const char *numstr, long long minval, long long maxval,-
35 const char **errstrp)-
36{-
37 long long ll = 0;-
38 char *ep;-
39 int error = 0;-
40 struct errval {-
41 const char *errstr;-
42 int err;-
43 } ev[4] = {-
44 { NULL, 0 },-
45 { "invalid", EINVAL },-
46 { "too small", ERANGE },-
47 { "too large", ERANGE },-
48 };-
49-
50 ev[0].err = errno;-
51 errno = 0;-
52 if (minval > maxval)
minval > maxvalDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • sshd
0-2
53 error = INVALID;
never executed: error = 1;
0
54 else {-
55 ll = strtoll(numstr, &ep, 10);-
56 if (numstr == ep || *ep != '\0')
numstr == epDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • sshd
*ep != '\0'Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • sshd
0-2
57 error = INVALID;
never executed: error = 1;
0
58 else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
ll == (-0x7fff...fffffLL - 1LL)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • sshd
(*__errno_location ()) == 34Description
TRUEnever evaluated
FALSEnever evaluated
ll < minvalDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • sshd
0-2
59 error = TOOSMALL;
never executed: error = 2;
0
60 else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval)
ll == 0x7fffffffffffffffLLDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • sshd
(*__errno_location ()) == 34Description
TRUEnever evaluated
FALSEnever evaluated
ll > maxvalDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • sshd
0-2
61 error = TOOLARGE;
never executed: error = 3;
0
62 }
executed 2 times by 1 test: end of block
Executed by:
  • sshd
2
63 if (errstrp != NULL)
errstrp != ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • sshd
FALSEnever evaluated
0-2
64 *errstrp = ev[error].errstr;
executed 2 times by 1 test: *errstrp = ev[error].errstr;
Executed by:
  • sshd
2
65 errno = ev[error].err;-
66 if (error)
errorDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • sshd
0-2
67 ll = 0;
never executed: ll = 0;
0
68-
69 return (ll);
executed 2 times by 1 test: return (ll);
Executed by:
  • sshd
2
70}-
71-
72#endif /* HAVE_STRTONUM */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2