Problem getting "memory cannot be read" 
Author Message
 Problem getting "memory cannot be read"

I'm writing a little win32 console app and getting a runtime error "memory
cannot be read". Below is the function where this error occurs. Here below
as well, is the s1 and s2 data being passed to it.

I think tolower() is causing the runtime error. s1 showing a null and s2
show the string. Confused why tolower function is burping.

Apprecaite help on this one.
Jt

+ s1 0xcccccccc ""
+ s2 0x0012fc5c "global string"

static Boolean_T StrEq(char *s1, char *s2)
{
 while (tolower(*s1) == tolower(*s2))
 {
  if (NUL == *s1)
     return True_;
   s1++;
   s2++;
 }

return False_;

Quote:
}



Wed, 23 Feb 2005 07:45:37 GMT  
 Problem getting "memory cannot be read"

Quote:

>I'm writing a little win32 console app and getting a runtime error "memory
>cannot be read". Below is the function where this error occurs. Here below
>as well, is the s1 and s2 data being passed to it.

>I think tolower() is causing the runtime error. s1 showing a null and s2
>show the string. Confused why tolower function is burping.

>+ s1 0xcccccccc ""

      ^^^^^^^^^^
That doesn't smell like a valid pointer value. I think you've
forgotten to initialise a string pointer somewhere.

Quote:
>+ s2 0x0012fc5c "global string"

>static Boolean_T StrEq(char *s1, char *s2)
>{
> while (tolower(*s1) == tolower(*s2))
> {
>  if (NUL == *s1)
>     return True_;
>   s1++;
>   s2++;
> }
>return False_;
>}

-- Mat.


Wed, 23 Feb 2005 08:22:11 GMT  
 Problem getting "memory cannot be read"

Quote:

>I'm writing a little win32 console app and getting a runtime error "memory
>cannot be read". Below is the function where this error occurs. Here below
>as well, is the s1 and s2 data being passed to it.

>I think tolower() is causing the runtime error. s1 showing a null and s2
>show the string. Confused why tolower function is burping.

>Apprecaite help on this one.
>Jt

>+ s1 0xcccccccc ""
>+ s2 0x0012fc5c "global string"

>static Boolean_T StrEq(char *s1, char *s2)
>{
> while (tolower(*s1) == tolower(*s2))
> {
>  if (NUL == *s1)
>     return True_;
>   s1++;
>   s2++;
> }

>return False_;
>}

I assume that NUL, True_, and False_ are defined sensibly somewhere;
same with Boolean_T; none of them are standard.

You should check both pointers for non-NULL-ness, before entering
your while() loop; as it stands, this will crash if either one is NULL.
Are you sure you are passing "", and not NULL?

And within the loop, you should check both *s1 and *s2 for == '\0'
condition; as it stands now, if string s2 is shorter than s1, you
once again crash.

Also: since you are already using non-portable code anyway, you might
wish to check your implementation's documentation for the non-standard
function strcasecmp(), or stricmp().

--Ben

--



Wed, 23 Feb 2005 09:02:15 GMT  
 Problem getting "memory cannot be read"

Quote:
> I'm writing a little win32 console app and getting a runtime error
> "memory cannot be read". Below is the function where this error
> occurs. Here below as well, is the s1 and s2 data being passed to it.

> I think tolower() is causing the runtime error. s1 showing a null and
> s2 show the string. Confused why tolower function is burping.

> + s1 0xcccccccc ""

Weird value for a pointer. Please check the way the function is called. If
not standard, details on :


Quote:
> + s2 0x0012fc5c "global string"

> static Boolean_T StrEq(char *s1, char *s2)

'Boolean_T' undefined. What's wrong with int.

Quote:
> {
>  while (tolower(*s1) == tolower(*s2))
>  {
>   if (NUL == *s1)

Assuming NULL. Please don't retype, but copy & paste.

Quote:
>      return True_;

'True_' undefined. What's wrong with 1.

Quote:
>    s1++;
>    s2++;
>  }

> return False_;

'False_' undefined. What's wrong with 0.

Quote:
> }

--
-ed- emdel at noos.fr ~]=[o
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
C-library: http://www.dinkumware.com/htm_cl/index.html
"Mal nommer les choses c'est ajouter du malheur au monde."
-- Albert Camus.


Wed, 23 Feb 2005 16:44:34 GMT  
 Problem getting "memory cannot be read"

Quote:


>> static Boolean_T StrEq(char *s1, char *s2)
>> {
>>  while (tolower(*s1) == tolower(*s2))

You should cast *s1 and *s2 to unsigned char.

Quote:
>>  {
>>   if (NUL == *s1)
> Assuming NULL. Please don't retype, but copy & paste.

Comparing a character to NULL is bad and requires a diagnostic if NULL
has pointer type. NUL is probably defined as '\0' somewhere.

--
Stefan Farfeleder



Wed, 23 Feb 2005 22:00:08 GMT  
 Problem getting "memory cannot be read"

Quote:



> >+ s1 0xcccccccc ""
> >+ s2 0x0012fc5c "global string"

I don't understand the above at all.

Quote:

> >static Boolean_T StrEq(char *s1, char *s2)
> >{
> > while (tolower(*s1) == tolower(*s2))
> > {
> >  if (NUL == *s1)
> >     return True_;
> >   s1++;
> >   s2++;
> > }

> >return False_;
> >}

> I assume that NUL, True_, and False_ are defined sensibly somewhere;
> same with Boolean_T; none of them are standard.

> You should check both pointers for non-NULL-ness, before entering
> your while() loop; as it stands, this will crash if either one is NULL.
> Are you sure you are passing "", and not NULL?

> And within the loop, you should check both *s1 and *s2 for == '\0'
> condition; as it stands now, if string s2 is shorter than s1, you
> once again crash.

Nope. If *s2 is 0 the while condition fails and the function exits with
False_.

Quote:

> Also: since you are already using non-portable code anyway, you might
> wish to check your implementation's documentation for the non-standard
> function strcasecmp(), or stricmp().

> --Ben

> --

--

"Everything should be made as simple as possible, but not simpler."
                    --- Albert Einstein ---


Wed, 23 Feb 2005 22:10:24 GMT  
 Problem getting "memory cannot be read"

Quote:
>>>   if (NUL == *s1)

>> Assuming NULL. Please don't retype, but copy & paste.

> Comparing a character to NULL is bad and requires a diagnostic if NULL
> has pointer type. NUL is probably defined as '\0' somewhere.

True enough. I has read badly. To the OP, sorry about that.

--
-ed- emdel at noos.fr ~]=[o
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
C-library: http://www.dinkumware.com/htm_cl/index.html
"Mal nommer les choses c'est ajouter du malheur au monde."
-- Albert Camus.



Thu, 24 Feb 2005 00:02:08 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. "Memory cannot be read"?

2. ERROR: memory cannot be "read"

3. Error "free"-ing "malloc"-ed memory

4. Memory could not be "read"

5. memory "read" error

6. ERROR: memory could not be "read"

7. The memory could not be "read"

8. The memory could not be "read"

9. Help to solve problem with "gets()"

10. Problems freeing memory using "free"

11. When using Dumpin.exe I am getting "T / : error : cannot execute LINK.EXE"

12. "No memory" while plenty of memory

 

 
Powered by phpBB® Forum Software