1

Topic: How correctly to obtain the data from STORAGE_BUS_TYPE

I receive value from STORAGE_BUS_TYPE busType for HDD and USB-flash on the PC (Win7) and a notebook (WinXP).
[spoiler busType from HDD and USB-flash]

char* strDD;
char* strBT;
if (pDeviceDescriptor-> ProductIdOffset! = 0) {
strDD = (char *) ((char *) pDeviceDescriptor + pDeviceDescriptor-> ProductIdOffset);
}
busType = pDeviceDescriptor-> BusType;
/* 1 variant - simply numerical value */
sprintf (strDD, "%s %d", strDD, busType);
/* 2 variant - I transport in tekst*/
if (busType! = 0) {
switch (busType)
{
...
case BusTypeScsi://0x1
strBT = "BusTypeScsi";
break;
...
default:
strBT = "default";
}
sprintf (strDD, "%s %s", strDD, strBT);
}
///////////////
MessageBox (
NULL;
strDD;
"DeviceDescriptor";
MB_OK | MB_ICONINFORMATION);

[/spoiler]
On the PC 1st and 2nd variants work for HDD, but does not work for USB-flash
[spoiler Error for USB-flash]
---------------------------
Microsoft Visual C ++ Runtime Library
---------------------------
Debug Error!
Program:...
HEAP CORRUPTION DETECTED: after Normal block (#62) at 0x006D7BF0.
CRT detected that the application wrote to memory after end of heap buffer.
...
[/spoiler]
2nd variant on a notebook does not work neither for HDD, nor for USB-flash, application simply falls.
How correctly to obtain the data from STORAGE_BUS_TYPE in a numerical and text type for data output that everywhere worked?

2

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

AIS;
At least here it should not be.

sprintf (>>> strDD <<<, "%s %d",>>> strDD <<<, busType);

Well and generally there are doubts that in strDD it is possible to write something.

3

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

Anatoly Moskovsky wrote:

AIS;
At least here it should not be.

sprintf (>>> strDD <<<, "%s %d",>>> strDD <<<, busType);

Well and generally there are doubts that in strDD it is possible to write something.

I.e. it is necessary to collect all data which it is necessary to me, to a heap, and then one call sprintf to generate a line for an output. So? Or how differently the such gathers in uniform?
. Thanks for comments, councils and the help and at this forum smile

4

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

AIS wrote:

it is passed...
I.e. it is necessary to collect all data which it is necessary to me, to a heap, and then one call sprintf to generate a line for an output. So? Or how differently the such gathers in uniform?
. Thanks for comments, councils and the help and at this forum smile

Yes figs you knows that it is necessary to you. The Narcomansky any code absolutely...
Formulate a question correctly then you will receive the answer.

5

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

AIS wrote:

I.e. it is necessary to collect all data which it is necessary to me, to a heap, and then one call sprintf to generate a line for an output. So? Or how differently the such gathers in uniform?

strDD specifies in the field in dynamic part STORAGE_DEVICE_DESCRIPTOR.
I on 100 % am assured that in this field it is impossible to add anything.
And on 99 % it is assured that generally this structure not should to be modified by the user.

6

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

AIS, at you on a heap structure DeviceDescriptor with member-index ProductIdOffset for any line also lying in any section of a heap lies. Then you sprintf tries to generate on the same section of a heap the new formatted line explicitly  the size, simultaneously finding therefrom  that there was. Not subtly that your heap collapses on time! smile))
And that you expected? Go, learn !

7

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

Anatoly Moskovsky wrote:

it is passed...
strDD specifies in the field in dynamic part STORAGE_DEVICE_DESCRIPTOR.
I on 100 % am assured that in this field it is impossible to add anything.
And on 99 % it is assured that generally this structure not should to be modified by the user.

strDD - I recognize, did not think.
[spoiler So already like all earned]

...
size_t sLen = strlen (strDD) + strlen (strBT);
char *strReturn = (char *) malloc (sizeof (char) * (sLen+1));
sprintf (strReturn, "DEVICE: %s %s", strDD, strBT);
...

[/spoiler]
Thank you very much.

8

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

AIS wrote:

So already like all earned

...
size_t sLen = strlen (strDD) + strlen (strBT);
char *strReturn = (char *) malloc (sizeof (char) * (sLen+1));
sprintf (strReturn, ">>> DEVICE: <<<%s>>> <<<%s", strDD, strBT);
...

and on DEVICE and gaps Pushkin will select storage?))

9

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

egorych wrote:

and on DEVICE and gaps Pushkin will select storage?))

To what these formalities by operation with a heap? smile))

10

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

egorych wrote:

it is passed...
And on DEVICE and gaps Pushkin will select storage?))

, again hurried smile))
Ah yes Pushkin, ah yes son of a bitch ()

NekZ wrote:

it is passed...
To what these formalities by operation with a heap? smile))

And on its breast the mighty one medal hung a heap () smile))

11

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

AIS, I would like to look in eyes to that who taught you Si...

char* buf = NULL;
size_t sz = 0;
buf = (char *) malloc (++ (sz = snprintf (buf, sz, "%s", test)));
snprintf (buf, sz, "%s", test);

12

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

rdb_dev wrote:

AIS, I would like to look in eyes to that who taught you Si...

well, correct  would write this all to one line:-Q

13

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

CEMb, matter is not in one line, and that snprintf is able to return the amount of the characters necessary for layout of the formatted line. It is possible to Write both to some lines and for understanding so even it is better:

static const char fmt_DEVICE [] = "DEVICE: %s %s";
char* buf = NULL;
size_t sz = 0;
sz = snprintf (buf, sz, fmt_DEVICE, strDD, strBT);
sz ++;
buf = (char *) malloc (sz);
if (NULL! = buf)
sprintf (buf, sz, fmt_DEVICE, strDD, strBT);

14

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

rdb_dev wrote:

CEMb, matter is not in one line, and that snprintf is able to return the amount of the characters necessary for layout of the formatted line. It is possible to Write both to some lines and for understanding so even it is better:

static const char fmt_DEVICE [] = "DEVICE: %s %s";
char* buf = NULL;
size_t sz = 0;
sz = snprintf (buf, sz, fmt_DEVICE, strDD, strBT);
sz ++;
buf = (char *) malloc (sz);
if (NULL! = buf)
>>> sprintf <<<(buf, sz, fmt_DEVICE, strDD, strBT);

Certainly, the previous code was more interesting, praise to that "who taught you Si" wink
I too would want to look to it in eyes and to learn, that it would deliver you for this code)))
. "We certainly did not finish universities" (), therefore for both codes of thanks.

15

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

AIS, you also do not distinguish a misprint from the basic error... Nasty.
P.S. I too did not finish universities that did not prevent me to master in 9th class assembler Z-80 without someone's help.

16

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

rdb_dev wrote:

matter is not in one line, and that snprintf is able to return an amount of characters;
Necessary for layout of the formatted line.

Aha, or-1 at an error. Your code rolled half a century ago, but since then some
Programmers started to care of that them  did not fall with exclamation " ".

17

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

Dimitry Sibiryakov, will not be any "shit happen" by a call snprintf with the size of the buffer 0 neither on one of platforms - nor on , on . Everywhere the demanded size of characters will be produced.

18

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

rdb_dev wrote:

the demanded size of characters Everywhere will be produced.

I repeat slowly: or-1 at an error .

19

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

Dimitry Sibiryakov wrote:

I Repeat slowly: or-1 at an error .

at what error? At null pointer for a line of a format?

20

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

rdb_dev wrote:

At what error?

At any error.

21

Re: How correctly to obtain the data from STORAGE_BUS_TYPE

Dimitry Sibiryakov wrote:

it is passed...
At any error.

Here specific code location:

static const char fmt_DEVICE [] = "DEVICE: %s %s";
char* buf = NULL;
size_t sz = 0;
sz = snprintf (buf, sz, fmt_DEVICE, strDD, strBT);

Specify, please, in origin conditions of "any error" thus that strDD and strBT specify for correctly generated lines in one-byte national or ASCII to the coding.