Strange Problem-variable value getting changed

hi all,

OS:- windows NT 4.0
H/w:- pci card.

In this following code snippet, I am sending the busID parameter to the
function. In the 1st and 2nd KdPrint, I am getting the exact busID value of
0, but in the 3rd KdPrint, the value of busID gets changed to 48 or some
arbitrary value.

I am not able to figure out how this could happen…

NTSTATUS
CreateDevice(IN PDRIVER_OBJECT drvObj, IN PUNICODE_STRING regPath,ULONG
busID,
ULONG slotId, IN PPCI_COMMON_CONFIG pciData)
{

WCHAR devNameBuf = L"\Device\Test0";
UNICODE_STRING devNameUniStr;
WCHAR devLinkBuf = L"\DosDevices\TEST";

KdPrint((“Bus ID :%d”, busID));==========================>1
devNameBuf[sizeof(devNameBuf) - 2] = L’0’ + devNum;
KdPrint((“Bus ID :%d”, busID));=============================>2
devLinkBuf[sizeof(devLinkBuf) - 2] = L’0’ + devNum;
devNum++;
KdPrint((“Bus ID :%d”, busID));=================================>3




}

Can somebody throw some light on this…

Thanx,

Ashok

THIS E-MAIL MESSAGE ALONG WITH ANY ATTACHMENTS IS INTENDED ONLY FOR THE ADDRESSEE
and may contain confidential and privileged information. If the reader of this message
is not the intended recipient, you are notified that any dissemination, distribution
or copy of this communication is strictly Prohibited.If you have received this message
by error, please notify the sender immediately, return the original mail to the sender
and delete the message from your system.

Strange problem! After all it is a ‘variable’ and not a constant :wink:

Govind

-----Original Message-----
From: Ashok Kumar [mailto:xxxxx@rassit.com]
Sent: Wednesday, February 05, 2003 5:04 PM
To: NT Developers Interest List
Subject: [ntdev] Strange Problem-variable value getting changed


You are currently subscribed to ntdev as: xxxxx@nestec.net
To unsubscribe send a blank email to xxxxx@lists.osr.com

Comment variable “devNum” and try it ? I guess there is some overflow.

Regards,
int3
----- Original Message -----
From: Ashok Kumar
To: NT Developers Interest List
Sent: Wednesday, February 05, 2003 5:04 PM
Subject: [ntdev] Strange Problem-variable value getting changed

THIS E-MAIL MESSAGE ALONG WITH ANY ATTACHMENTS IS INTENDED ONLY FOR THE ADDRESSEE
and may contain confidhi all,

OS:- windows NT 4.0
H/w:- pci card.

In this following code snippet, I am sending the busID parameter to the function. In the 1st and 2nd KdPrint, I am getting the exact busID value of 0, but in the 3rd KdPrint, the value of busID gets changed to 48 or some arbitrary value.

I am not able to figure out how this could happen…

NTSTATUS
CreateDevice(IN PDRIVER_OBJECT drvObj, IN PUNICODE_STRING regPath,ULONG busID,
ULONG slotId, IN PPCI_COMMON_CONFIG pciData)
{

WCHAR devNameBuf = L"\Device\Test0";
UNICODE_STRING devNameUniStr;
WCHAR devLinkBuf = L"\DosDevices\TEST";

KdPrint((“Bus ID :%d”, busID));==========================>1
devNameBuf[sizeof(devNameBuf) - 2] = L’0’ + devNum;
KdPrint((“Bus ID :%d”, busID));=============================>2
devLinkBuf[sizeof(devLinkBuf) - 2] = L’0’ + devNum;
devNum++;
KdPrint((“Bus ID :%d”, busID));=================================>3




}

Can somebody throw some light on this…

Thanx,

Ashok

The statements like
devNameBuf[sizeof(devNameBuf) - 2] = L’0’ + devNum;
must be corrected to
devNameBuf[sizeof(devNameBuf)/sizeof(WCHAR) - 2] = L’0’ + devNum;

Wbr Joze


Joze Fabcic
e-mail: xxxxx@hermes.si
www: http://www.hermes.si
HERMES SoftLab, Office Nova Gorica
Erjavceva 2, 5000 Nova Gorica, Slovenia
phone: (+386 5) 33 32 650, (+386 1) 58 65 700
fax: (+386 5) 33 32 656, (+386 1) 58 65 270

----- Original Message -----
From: Ashok Kumar

In this following code snippet, I am sending the busID parameter to the
function. In the 1st and 2nd KdPrint, I am getting the exact busID value of
0, but in the 3rd KdPrint, the value of busID gets changed to 48 or some
arbitrary value.

I am not able to figure out how this could happen…

NTSTATUS
CreateDevice(IN PDRIVER_OBJECT drvObj, IN PUNICODE_STRING regPath,ULONG
busID,
ULONG slotId, IN PPCI_COMMON_CONFIG pciData)
{

WCHAR devNameBuf = L"\Device\Test0";
UNICODE_STRING devNameUniStr;
WCHAR devLinkBuf = L"\DosDevices\TEST";

KdPrint((“Bus ID :%d”, busID));==========================>1
devNameBuf[sizeof(devNameBuf) - 2] = L’0’ + devNum;
KdPrint((“Bus ID :%d”, busID));=============================>2
devLinkBuf[sizeof(devLinkBuf) - 2] = L’0’ + devNum;
devNum++;
KdPrint((“Bus ID :%d”, busID));=================================>3

Isn’t it interesting that “the value of busID gets changed to
48_or_some_arbitrary_value”?

=)

Chuck

----- Original Message -----
From: “Joze Fabcic”
To: “NT Developers Interest List”
Sent: Wednesday, February 05, 2003 7:19 PM
Subject: [ntdev] Re: Strange Problem-variable value getting changed

> The statements like
> devNameBuf[sizeof(devNameBuf) - 2] = L’0’ + devNum;
> must be corrected to
> devNameBuf[sizeof(devNameBuf)/sizeof(WCHAR) - 2] = L’0’ + devNum;
>
> Wbr Joze
>
> -----------------------------------------------
> Joze Fabcic
> e-mail: xxxxx@hermes.si
> www: http://www.hermes.si
> HERMES SoftLab, Office Nova Gorica
> Erjavceva 2, 5000 Nova Gorica, Slovenia
> phone: (+386 5) 33 32 650, (+386 1) 58 65 700
> fax: (+386 5) 33 32 656, (+386 1) 58 65 270
> -----------------------------------------------
>
> ----- Original Message -----
> From: Ashok Kumar
>
> In this following code snippet, I am sending the busID parameter to
the
> function. In the 1st and 2nd KdPrint, I am getting the exact busID
value of
> 0, but in the 3rd KdPrint, the value of busID gets changed to 48 or
some
> arbitrary value.
>
> I am not able to figure out how this could happen…
>
>
> NTSTATUS
> CreateDevice(IN PDRIVER_OBJECT drvObj, IN PUNICODE_STRING
regPath,ULONG
> busID,
> ULONG slotId, IN PPCI_COMMON_CONFIG pciData)
> {
>
>
> WCHAR devNameBuf = L"\Device\Test0";
> UNICODE_STRING devNameUniStr;
> WCHAR devLinkBuf = L"\DosDevices\TEST";
>
>
> KdPrint((“Bus ID :%d”, busID));==========================>1
> devNameBuf[sizeof(devNameBuf) - 2] = L’0’ + devNum;
> KdPrint((“Bus ID :%d”, busID));=============================>2
> devLinkBuf[sizeof(devLinkBuf) - 2] = L’0’ + devNum;
> devNum++;
> KdPrint((“Bus ID :%d”, busID));=================================>3

Hi,

(Not sure if this is the cause !!!)

sizeof would return total num bytes. For WCHAR, it would be DOUBLE the
num chars in string.

hence,

ur index calculation should have been,

sizeof(devNameBuf)/2 - 1 ==> Here, “sizeof(devNameBuf)/2” would give
total num chars and when it is subtracted by 1, points last char.

INSTEAD OF

sizeof(devNameBuf) - 2.

This could be the reason for stack corruption and in consequence, the
variable is corrupted.

Please let me know if this solves ur prob.

Thanks,
Sathya
-----Original Message-----
From: Ashok Kumar [mailto:xxxxx@rassit.com]
Sent: Wednesday, February 05, 2003 5:04 PM
Subject: Strange Problem-variable value getting changed

hi all,

OS:- windows NT 4.0
H/w:- pci card.

In this following code snippet, I am sending the busID parameter to the
function. In the 1st and 2nd KdPrint, I am getting the exact busID value
of 0, but in the 3rd KdPrint, the value of busID gets changed to 48 or
some arbitrary value.

I am not able to figure out how this could happen…

NTSTATUS
CreateDevice(IN PDRIVER_OBJECT drvObj, IN PUNICODE_STRING regPath,ULONG
busID,
ULONG slotId, IN PPCI_COMMON_CONFIG pciData)
{

WCHAR devNameBuf = L"\Device\Test0";
UNICODE_STRING devNameUniStr;
WCHAR devLinkBuf = L"\DosDevices\TEST";

KdPrint((“Bus ID :%d”, busID));==========================>1
devNameBuf[sizeof(devNameBuf) - 2] = L’0’ + devNum;
KdPrint((“Bus ID :%d”, busID));=============================>2
devLinkBuf[sizeof(devLinkBuf) - 2] = L’0’ + devNum;
devNum++;
KdPrint((“Bus ID :%d”, busID));=================================>3




}

Can somebody throw some light on this…

Thanx,

Ashok

THIS E-MAIL MESSAGE ALONG WITH ANY ATTACHMENTS IS INTENDED ONLY FOR THE
ADDRESSEE
and may contain confidential and privileged information. If the reader
of this message
is not the intended recipient, you are notified that any dissemination,
distribution
or copy of this communication is strictly Prohibited.If you have
received this message
by error, please notify the sender immediately, return the original mail
to the sender
and delete the message from your system.

Is this your first C program ? You might want to avoid device-drivers for a
little while if so, because they can be a tad tricky to debug otherwise.

Let’s check the obvious … did you use RtlInitUnicodeString in your driver
? Are you using \.\TES0 syntax in your usermode program (for devLinkBuf
you did not allocate enough space for a trailing number).

HTH
-Paul

-----Original Message-----
From: Ashok Kumar [mailto:xxxxx@rassit.com]
Sent: Wednesday, February 05, 2003 10:36 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Strange Problem-variable value getting changed

Hi

Thanks for all ur replies

Sathya… i substituted the expression as u suggested, but with no luck…
now i am albe to get the proper value in the variable…but the problem now
is that iam not able to open the handle to the device with that name…
my CreateFile returns me an INVALID_HANDLE_VALUE …

I even tried the suggestions by Joze Fabcic…
But the same problem is arising with it as well…

what else could be the cause??

with regards
Ashok

-------Original Message-------

From: NT Developers Interest List
Date: Thursday, February 06, 2003 11:27:02 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Strange Problem-variable value getting changed

Hi,

(Not sure if this is the cause !!!)

sizeof would return total num bytes. For WCHAR, it would be DOUBLE the
num chars in string.

hence,

ur index calculation should have been,

sizeof(devNameBuf)/2 - 1 ==> Here, “sizeof(devNameBuf)/2” would give
total num chars and when it is subtracted by 1, points last char.

INSTEAD OF

sizeof(devNameBuf) - 2.

This could be the reason for stack corruption and in consequence, the
variable is corrupted.

Please let me know if this solves ur prob.

Thanks,
Sathya
-----Original Message-----
From: Ashok Kumar [mailto:xxxxx@rassit.com]
Sent: Wednesday, February 05, 2003 5:04 PM
Subject: Strange Problem-variable value getting changed

hi all,

OS:- windows NT 4.0
H/w:- pci card.

In this following code snippet, I am sending the busID parameter to the
function. In the 1st and 2nd KdPrint, I am getting the exact busID value
of 0, but in the 3rd KdPrint, the value of busID gets changed to 48 or
some arbitrary value.

I am not able to figure out how this could happen…

NTSTATUS
CreateDevice(IN PDRIVER_OBJECT drvObj, IN PUNICODE_STRING regPath,ULONG
busID,
ULONG slotId, IN PPCI_COMMON_CONFIG pciData)
{

WCHAR devNameBuf = L"\Device\Test0";
UNICODE_STRING devNameUniStr;
WCHAR devLinkBuf = L"\DosDevices\TEST";

KdPrint((“Bus ID :%d”, busID));==========================>1
devNameBuf[sizeof(devNameBuf) - 2] = L’0’ + devNum;
KdPrint((“Bus ID :%d”, busID));=============================>2
devLinkBuf[sizeof(devLinkBuf) - 2] = L’0’ + devNum;
devNum++;
KdPrint((“Bus ID :%d”, busID));=================================>3

.
.
.
}

Can somebody throw some light on this…

Thanx,

Ashok