Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: lib/libc/atoi.c

Issue 1731653002: Allow for null endptr (Closed) Base URL: https://github.com/littlekernel/lk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ** Copyright 2001, Travis Geiselbrecht. All rights reserved. 2 ** Copyright 2001, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License. 3 ** Distributed under the terms of the NewOS License.
4 */ 4 */
5 /* 5 /*
6 * Copyright (c) 2008 Travis Geiselbrecht 6 * Copyright (c) 2008 Travis Geiselbrecht
7 * 7 *
8 * Permission is hereby granted, free of charge, to any person obtaining 8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files 9 * a copy of this software and associated documentation files
10 * (the "Software"), to deal in the Software without restriction, 10 * (the "Software"), to deal in the Software without restriction,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 159
160 if (c >= 'A' && c <= 'Z') { 160 if (c >= 'A' && c <= 'Z') {
161 v = c - 'A' + 10; 161 v = c - 'A' + 10;
162 } else if (c >= 'a' && c <= 'z') { 162 } else if (c >= 'a' && c <= 'z') {
163 v = c - 'a' + 10; 163 v = c - 'a' + 10;
164 } else if (c >= '0' && c <= '9') { 164 } else if (c >= '0' && c <= '9') {
165 v = c - '0'; 165 v = c - '0';
166 } 166 }
167 167
168 if (v < 0 || v >= base) { 168 if (v < 0 || v >= base) {
169 *endptr = (char *) nptr; 169 if (endptr) {
170 *endptr = (char *) nptr;
171 }
170 break; 172 break;
171 } 173 }
172 174
173 new_ret = ret * base; 175 new_ret = ret * base;
174 if (new_ret / base != ret || 176 if (new_ret / base != ret ||
175 new_ret + v < new_ret || 177 new_ret + v < new_ret ||
176 ret == ULONG_MAX) { 178 ret == ULONG_MAX) {
177 ret = ULONG_MAX; 179 ret = ULONG_MAX;
178 errno = ERANGE; 180 errno = ERANGE;
179 } else { 181 } else {
180 ret = new_ret + v; 182 ret = new_ret + v;
181 } 183 }
182 184
183 nptr++; 185 nptr++;
184 } 186 }
185 187
186 if (neg && ret != ULONG_MAX) { 188 if (neg && ret != ULONG_MAX) {
187 ret = -ret; 189 ret = -ret;
188 } 190 }
189 191
190 return ret; 192 return ret;
191 } 193 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698