Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #164078
| From | Meredith Montgomery <mmontgomery@levado.to> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: unsafe C |
| Date | 2021-12-25 21:41 -0300 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <86sfug19l8.fsf@levado.to> (permalink) |
| References | <d8227134-6e0b-486e-af91-aeece50a466bn@googlegroups.com> <54ebbb14-cb1e-4dd5-a4ec-9dd086e0eaa3n@googlegroups.com> <86wnk153br.fsf@levado.to> <pos-20211219061641@ram.dialup.fu-berlin.de> |
ram@zedat.fu-berlin.de (Stefan Ram) writes:
> Meredith Montgomery <mmontgomery@levado.to> writes:
>>> it is funny that this is a warning and not an error.
>
>>int scan_ulong(register char *s, register unsigned long *u)
>>{
>> register unsigned int pos;
> ...
>> return pos;
>>}
>
> It returns the /unsigned/ int "pos", but its return type is
> declared /signed/ int?
>
> /u/ is accessed at most once in the function, but declared
> "register"?
Let's see. I don't think I would've changed that much, but I might.
Lol. I did. I can't even copy properly! Thanks for spotting that.
Hm, wait! The check for overflow is not his. It's mine. Alas, memory
failing me. Daniel J. Bernstein, sorry about that.
--8<---------------cut here---------------start------------->8---
/* Public domain. */
#include "scan.h"
unsigned int scan_ulong(register const char *s,register unsigned long *u)
{
register unsigned int pos = 0;
register unsigned long result = 0;
register unsigned long c;
while ((c = (unsigned long) (unsigned char) (s[pos] - '0')) < 10) {
result = result * 10 + c;
++pos;
}
*u = result;
return pos;
}
--8<---------------cut here---------------end--------------->8---
But, yes, he did qualify u with ``register''.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
unsafe C Thiago Adams <thiago.adams@gmail.com> - 2021-12-17 12:13 -0800
Re: unsafe C Thiago Adams <thiago.adams@gmail.com> - 2021-12-17 12:16 -0800
Re: unsafe C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-12-17 12:25 -0800
Re: unsafe C Meredith Montgomery <mmontgomery@levado.to> - 2021-12-18 12:40 -0300
Re: unsafe C Meredith Montgomery <mmontgomery@levado.to> - 2021-12-25 21:41 -0300
Re: unsafe C Meredith Montgomery <mmontgomery@levado.to> - 2021-12-25 21:42 -0300
Re: unsafe C Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-12-18 12:29 -0800
Re: unsafe C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-12-17 12:20 -0800
Re: unsafe C Thiago Adams <thiago.adams@gmail.com> - 2021-12-17 12:29 -0800
Re: unsafe C Peter 'Shaggy' Haywood <phaywood@alphalink.com.au> - 2021-12-19 17:16 +1100
Re: unsafe C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-12-19 13:32 -0800
Re: unsafe C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-12-17 20:30 +0000
Re: unsafe C Thiago Adams <thiago.adams@gmail.com> - 2021-12-17 12:35 -0800
csiph-web