Raised This Month: $32 Target: $400
 8% 

Solved Invalid memory access


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
RumbleFrog
Great Tester of Whatever
Join Date: Dec 2016
Location: Fish Tank
Old 05-05-2017 , 15:24   Invalid memory access
Reply With Quote #1

So I have this and I'm unable to write to string array or read from it.

PHP Code:
char Cache[][][255];

for (
int i 1<= RowCounti++)
{
    
results.FetchRow();
        
    
results.FetchString(1Cache[i][0], sizeof Cache[][]);
    
results.FetchString(2Cache[i][1], sizeof Cache[][]);
    
results.FetchString(5Cache[i][2], sizeof Cache[][]);

PHP Code:
[SMException reportedInvalid memory access 

Last edited by RumbleFrog; 05-07-2017 at 13:10.
RumbleFrog is offline
RumbleFrog
Great Tester of Whatever
Join Date: Dec 2016
Location: Fish Tank
Old 05-05-2017 , 15:26   Re: Invalid memory access
Reply With Quote #2

Also, would this be valid?

PHP Code:
char Message[] = Cache[Row][0]; 

Edit: Got my answer It's not valid.

Last edited by RumbleFrog; 05-05-2017 at 15:35.
RumbleFrog is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 05-05-2017 , 15:59   Re: Invalid memory access
Reply With Quote #3

Change
PHP Code:
sizeof Cache[][] 
to
PHP Code:
sizeof(Cache[][]) 
P.S. Or this valid?

Last edited by Kailo; 05-05-2017 at 16:00.
Kailo is offline
RumbleFrog
Great Tester of Whatever
Join Date: Dec 2016
Location: Fish Tank
Old 05-05-2017 , 16:07   Re: Invalid memory access
Reply With Quote #4

Quote:
Originally Posted by Kailo View Post
Change
PHP Code:
sizeof Cache[][] 
to
PHP Code:
sizeof(Cache[][]) 
P.S. Or this valid?
They're the same though
RumbleFrog is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 05-05-2017 , 17:35   Re: Invalid memory access
Reply With Quote #5

How do you create the Cache?

Can you post a complete testcase?
__________________
Peace-Maker is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-05-2017 , 19:48   Re: Invalid memory access
Reply With Quote #6

Code:
char Cache[][][255];
This shouldn't compile, but does in global scope. If moved into a function, it correctly fails.

Last edited by Fyren; 05-05-2017 at 19:49. Reason: argh
Fyren is offline
RumbleFrog
Great Tester of Whatever
Join Date: Dec 2016
Location: Fish Tank
Old 05-05-2017 , 21:22   Re: Invalid memory access
Reply With Quote #7

Quote:
Originally Posted by Fyren View Post
Code:
char Cache[][][255];
This shouldn't compile, but does in global scope. If moved into a function, it correctly fails.
What should I use then?
RumbleFrog is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-05-2017 , 22:06   Re: Invalid memory access
Reply With Quote #8

You have to set the sizes if you want it to be global. Alternatively, use ArrayLists.
Fyren is offline
RumbleFrog
Great Tester of Whatever
Join Date: Dec 2016
Location: Fish Tank
Old 05-07-2017 , 13:10   Re: Invalid memory access
Reply With Quote #9

Quote:
Originally Posted by Fyren View Post
You have to set the sizes if you want it to be global. Alternatively, use ArrayLists.
Thanks, this did it. #IBlameTheCompiler
RumbleFrog is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-07-2017 , 15:37   Re: Invalid memory access
Reply With Quote #10

While it's true that it should have errored on compile, it's also true that the declaration is nonsense. Something like this only works because the compiler can count the sizes and fill in the blanks:

Code:
char arr[][255] = { "foo", "bar", "baz" };
Fyren is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:05.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode