Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #147696
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <kst-u@mib.org> |
| Newsgroups | comp.lang.c |
| Subject | Re: What are the odds? (a continuation of One works ...) |
| Date | Wed, 06 Nov 2019 19:19:06 -0800 |
| Organization | None to speak of |
| Lines | 30 |
| Message-ID | <ln36f05q6t.fsf@kst-u.example.com> (permalink) |
| References | <hxrwF.14017$2A5.601@fx38.iad> <d3d5se5l55l6abkkm0ja75scmepgsr4p03@4ax.com> <fQBwF.59470$Ko9.7309@fx48.iad> <vvv5sehh7oil3eb5dft8dun7s4t1rbt4h7@4ax.com> <voGwF.93833$vD7.57507@fx06.iad> <g4g6se5u1ggsmecioggck2k7ve59pfdbbp@4ax.com> <2VHwF.97943$_i.39059@fx25.am4> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | reader02.eternal-september.org; posting-host="fdd2727d9421cbcb7e0942d3891e7ce6"; logging-data="8363"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194nbvklT/pamII5T0dEOB8" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
| Cancel-Lock | sha1:uhUufmNg57jkuc1yQ7JQqK0Y1R8= sha1:gBFf8mznIRONpxf96bPblVflvrs= |
| Xref | csiph.com comp.lang.c:147696 |
Show key headers only | View raw
Bart <bc@freeuk.com> writes:
> On 06/11/2019 22:23, Barry Schwarz wrote:
>> On Wed, 6 Nov 2019 15:52:28 -0500, DFS <nospam@dfs.com> wrote:
>>> char charset[62] =
>>> "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
>> After numerous examples in your comp.lang.c posts (where I have
>> redirected this response since we are not discussing the odds any
>> more) of calculating charsetLen correctly, you have chosen to use a
>> different method. You have tried to pass charset to strlen in
>> complete violation of the requirements that function imposes.
>>
>> It is not sufficient to simply pass a pointer to char to strlen.
>> strlen requires that the pointer actually point to a string. In order
>> for an array of char to contain a string, the array must contain at
>> least one '\0' to properly terminate the string. charset does not.
>
> A simple fix is to get rid of the '62':
>
> char charset[] =
> "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
The only thing the code does that depends on charset containing a
valid string is the single (incorrect) call to strlen(). If you
replace `strlen(charset)` by `sizeof charset` then there's no need
to nul-terminate it.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: What are the odds? (a continuation of One works ...) Barry Schwarz <schwarzb@delq.com> - 2019-11-06 14:23 -0800
Re: What are the odds? (a continuation of One works ...) Bart <bc@freeuk.com> - 2019-11-06 22:35 +0000
Re: What are the odds? (a continuation of One works ...) luser droog <luser.droog@gmail.com> - 2019-11-06 17:09 -0800
Re: What are the odds? (a continuation of One works ...) Keith Thompson <kst-u@mib.org> - 2019-11-06 19:19 -0800
Re: What are the odds? (a continuation of One works ...) Ian Collins <ian-news@hotmail.com> - 2019-11-07 16:30 +1300
Re: What are the odds? (a continuation of One works ...) Bart <bc@freeuk.com> - 2019-11-07 10:59 +0000
Re: What are the odds? (a continuation of One works ...) David Brown <david.brown@hesbynett.no> - 2019-11-07 14:27 +0100
Re: What are the odds? (a continuation of One works ...) DFS <nospam@dfs.com> - 2019-11-06 18:09 -0500
Re: What are the odds? (a continuation of One works ...) Keith Thompson <kst-u@mib.org> - 2019-11-06 19:26 -0800
Re: What are the odds? (a continuation of One works ...) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-07 11:57 +0000
csiph-web