I ll try to explain the problem i am having.
There maybe syntax errors in code as i am just writing down a gist of the
main code…
AddtoTable(UNICODE_STRING x)
{
RtlInitUnicodeString(tab[count].name,L"qweruitewyuoitrewyurt");
RtlCopyUnicodeString(&tab[count].name,&x);
count++;
printtable();
}
The array tab of structures is global.
Above is a gist of the code i have written.
Basically the trouble is that whenever i make a change in one element of the
structure all the elements change.
i.e in the above if x is osronline initially then all the entries in my
array of struct is ‘osronline’(after the copy statement is executed). Now if
i change any one to ‘NT Developers’ all of the struct array entries change
to that. It is behaving as though each struct making the array is pointing
to the same buffer for the struct elements.
One more thing i have to mention is that if i separately initialise each
structure forming the array to different values then i do not have the
trouble. i.e if i have
RtlInitUnicodeString(tab[0].name,L"qweruitewyuoitrewyurt");
RtlInitUnicodeString(tab[1].name,L"asdfklsakdjflsakdflskjdf");
RtlInitUnicodeString(tab[2].name,L"xzcvzxcvx,m.cvm,cxnm");
then there is no overwriting problem.
I tried using a linked list to store the table i want. When i created my own
then also it overwrote the previous entries whenever i created a new node.
Same trouble i faced when i used LIST_ENTRY data structure. What is the
reason for this and how can i solve this problem?
Thanks in advance for any help.
Hi Shreyas,
Your C compiler has created a single unicode string L"qweruitewyuoitrewyurt"
in memory. Because you call RtlInitUnicodeString(), it points the Buffer
memory of all the UNICODE_STRING structs to point to the same buffer in
memory. What you want is a different buffer for each one. The basic error
you’ve made is that RtlInitUnicodeString() is intended for constant strings
that never get modified, but you’re calling RtlCopyUnicodeString() straight
afterwards to modify it.
Depending on what your data struct is storing and when, you should probably
allocate string buffers dynamically (using ExAllocatePool() or something).
However, here’s some rough code to illustrate the point using a global
buffer array:
#define MAX_STRING_LEN 64
#define NUMBER_OF_ENTRIES 32
WCHAR buffer[NUMBER_OF_ENTRIES][MAX_STRING_LEN];
void
AddtoTable(UNICODE_STRING x)
{
tab[count].name.Length = 0;
tab[count].name.MaximumLength = MAX_STRING_LEN*sizeof(WCHAR);
tab[count].name.Buffer = buffer[count];
RtlCopyUnicodeString(&tab[count].name,&x);
count++;
printtable();
}
Hope that helps,
Richard
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Shreyas Srivatsan
Sent: Tuesday, 6 June 2006 3:05 PM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] Very Odd Error
I ll try to explain the problem i am having.
There maybe syntax errors in code as i am just writing down a gist of the
main code…
AddtoTable(UNICODE_STRING x)
{
RtlInitUnicodeString(tab[count].name,L"qweruitewyuoitrewyurt");
RtlCopyUnicodeString(&tab[count].name,&x);
count++;
printtable();
}
The array tab of structures is global.
Above is a gist of the code i have written.
Basically the trouble is that whenever i make a change in one element of the
structure all the elements change.
i.e in the above if x is osronline initially then all the entries in my
array of struct is ‘osronline’(after the copy statement is executed). Now if
i change any one to ‘NT Developers’ all of the struct array entries change
to that. It is behaving as though each struct making the array is pointing
to the same buffer for the struct elements.
One more thing i have to mention is that if i separately initialise each
structure forming the array to different values then i do not have the
trouble. i.e if i have
RtlInitUnicodeString(tab[0].name,L"qweruitewyuoitrewyurt");
RtlInitUnicodeString(tab[1].name,L"asdfklsakdjflsakdflskjdf");
RtlInitUnicodeString(tab[2].name,L"xzcvzxcvx,m.cvm,cxnm");
then there is no overwriting problem.
I tried using a linked list to store the table i want. When i created my own
then also it overwrote the previous entries whenever i created a new node.
Same trouble i faced when i used LIST_ENTRY data structure. What is the
reason for this and how can i solve this problem?
Thanks in advance for any help.
— Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17 You are currently subscribed to
ntfsd as: xxxxx@spherical.com.au To unsubscribe send a blank email to
xxxxx@lists.osr.com
Thanks a lot. It worked. Now i can use this to implement my table in the
linked list. Actually am new to driver programming. I thought about the fact
that all must be pointing to the same buffer but i thought
RtlInitUnicodeString was the only way to initialise a unicodestring so i
persisted. Thanks again.