Thread: Re: AW: [Dev-C++] Strange phenomenon
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2002-10-24 12:32:42
|
Do you need to use BYTE? you seem to be typecasting a lot.
You've allocated memory with new
BYTE *CalledPartyNumberStruct = new BYTE[1024];
then used malloc to allocate more memory later, why is that?
>From: Christian Wallukat <Chr...@vo...>
>To: Daniel Glenfield <sp...@ho...>,
>dev...@li...
>Subject: AW: [Dev-C++] Strange phenomenon
>Date: Thu, 24 Oct 2002 14:18:29 +0200
>
>unsigned Connect(char CalledPartyNumber[1024], char
>CallingPartyNumber[1024])
>{
> _cmsg CMSG;
> int error;
> long Controller;
> unsigned short CIPValue;
>
>
>
> Controller = GetFreeController();
> if (Controller == -1)
> {
> /*----- if no available controller use the first one for
>correct -----*/
> /*----- error signaling -----*/
> Controller = 1;
> };
>
> int Connection = GetFreeLine();
>
> if (Connection == -1)
> {
> printf("Error: no available connection identifiers\n");
> /*----- no OS resources -----*/
> return 0x1108;
> };
>
>
>
> /*----- use ConnectionIdentifier as Messagenumber -----*/
> CONNECT_REQ_HEADER(&CMSG, (WORD)dwApplID, (unsigned short)Connection,
>Controller);
>
> /*----- build up service mask -----*/
>
> CONNECT_REQ_CIPVALUE(&CMSG) = 0x1;
>
> CONNECT_REQ_CALLEDPARTYNUMBER(&CMSG) = SetNumber
>(CalledPartyNumber);;
> CONNECT_REQ_CALLINGPARTYNUMBER(&CMSG) = SetNumber
>(CallingPartyNumber);
> CONNECT_REQ_B1PROTOCOL(&CMSG) = B1PROTOCOL;
> CONNECT_REQ_B2PROTOCOL(&CMSG) = B2PROTOCOL;
> CONNECT_REQ_B3PROTOCOL(&CMSG) = B3PROTOCOL;
> CONNECT_REQ_B3CONFIGURATION(&CMSG) = B3CONFIGURATION;
>
>
> return error;
>};
>
>
>
>
>
>
>
>
>BYTE *SetNumber(char Number[1024])
>{
> BYTE *CalledPartyNumberStruct = new BYTE[1024];
>
> if (strlen(Number) >= 1)
> {
> int len;
>
> len = strlen(Number);
>
> /*----- \xLen\x80 STRING '\0' -----*/
>
> CalledPartyNumberStruct = (unsigned char *)malloc(len + 2 +
>1);
>
> CalledPartyNumberStruct[0] = (unsigned char)(len + 1);
> CalledPartyNumberStruct[1] = 0x80;
>
> strcpy ((char *)&(CalledPartyNumberStruct[2]), Number);
> };
>
> return CalledPartyNumberStruct;
>};
>
>-----Ursprüngliche Nachricht-----
>Von: Daniel Glenfield [mailto:sp...@ho...]
>Gesendet am: Donnerstag, 24. Oktober 2002 14:14
>An: Chr...@vo...; dev...@li...
>Betreff: Re: [Dev-C++] Strange phenomenon
>
>Could be a scope problem. You'll need to show us the functions.
>
>
> >From: Christian Wallukat <Chr...@vo...>
> >To: "Dev-Cpp-Users@Lists. Sourceforge. Net (E-Mail)"
> ><dev...@li...>
> >Subject: [Dev-C++] Strange phenomenon
> >Date: Thu, 24 Oct 2002 13:51:23 +0200
> >
> >Hi List,
> >
> >
> >i have a strange phenomenon in my project:
> >
> >I call a function: Test(char szTest[1024]) with Test("test");
> >
> >In that function another Function (like the first) will be called:
> >Test2(szTest);
> >
> >the adress of szZest is 0x000000000....
> >
> >and the content is empty ....
> >
> >
> >Anyone an Idea ????
> >
> >Kind r
> >
> >Chris
> >
> >
> >-------------------------------------------------------
> >This sf.net email is sponsored by: Influence the future
> >of Java(TM) technology. Join the Java Community
> >Process(SM) (JCP(SM)) program now.
> >http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/javavote
> >_______________________________________________
> >Dev-cpp-users mailing list
> >Dev...@li...
> >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>_________________________________________________________________
>Get a speedy connection with MSN Broadband. Join now!
>http://resourcecenter.msn.com/access/plans/freeactivation.asp
_________________________________________________________________
Internet access plans that fit your lifestyle -- join MSN.
http://resourcecenter.msn.com/access/plans/default.asp
|
|
From: Per W. <pw...@ia...> - 2002-10-24 13:07:19
|
EMA System email: pw...@ia... Per Westermark web: http://iapetus.neab.net Vargvaegen 174B phone: +46 8 410 17 198 S-906 42 Umeaa Sweden On Thu, 24 Oct 2002, Daniel Glenfield wrote: > Do you need to use BYTE? you seem to be typecasting a lot. > You've allocated memory with new > BYTE *CalledPartyNumberStruct =3D new BYTE[1024]; > then used malloc to allocate more memory later, why is that? >=20 >=20 >=20 >=20 > >From: Christian Wallukat <Chr...@vo...> > >To: Daniel Glenfield <sp...@ho...>,=20 > >dev...@li... > >Subject: AW: [Dev-C++] Strange phenomenon > >Date: Thu, 24 Oct 2002 14:18:29 +0200 > > --> Is there a reason to declare the input parameters as arrays of --> characters? If the input is a string of digits, the logical --> input parameters would be: --> (const char CalledPartyNumber[],const char CallingPartyNumber[]) --> or: --> (const char* CalledPartyNumber,const char CallingPartyNumber) > >unsigned Connect(char CalledPartyNumber[1024], char > >CallingPartyNumber[1024]) > >{ > > _cmsg=09=09=09=09=09 CMSG; > > int=09=09=09=09=09 error; > > long=09=09=09=09=09 Controller; > > unsigned short=09=09=09 CIPValue; > > > > > > > > Controller =3D GetFreeController(); > > if (Controller =3D=3D -1) > >=09{ > >=09=09/*----- if no available controller use the first one for > >correct -----*/ > >=09=09/*----- error signaling -----*/ > >=09=09Controller =3D 1; > >=09}; > > > > int Connection =3D GetFreeLine(); > > > >=09if (Connection =3D=3D -1) > >=09{ > >=09=09printf("Error: no available connection identifiers\n"); > >=09=09/*----- no OS resources -----*/ > >=09=09return 0x1108; > > }; > > > > > > > >=09/*----- use ConnectionIdentifier as Messagenumber -----*/ > > CONNECT_REQ_HEADER(&CMSG, (WORD)dwApplID, (unsigned short)Connectio= n, > >Controller); > > > > /*----- build up service mask -----*/ > > > > CONNECT_REQ_CIPVALUE(&CMSG) =3D 0x1; > > > > CONNECT_REQ_CALLEDPARTYNUMBER(&CMSG) =3D SetNumber=20 > >(CalledPartyNumber);; > > CONNECT_REQ_CALLINGPARTYNUMBER(&CMSG) =3D SetNumber=20 > >(CallingPartyNumber); > > CONNECT_REQ_B1PROTOCOL(&CMSG) =3D B1PROTOCOL; > > CONNECT_REQ_B2PROTOCOL(&CMSG) =3D B2PROTOCOL; > > CONNECT_REQ_B3PROTOCOL(&CMSG) =3D B3PROTOCOL; > > CONNECT_REQ_B3CONFIGURATION(&CMSG) =3D B3CONFIGURATION; --> CMSG was declared inside this function. Does it have a destructor, --> or where will the numbers allocated by SetNumber calls be released? > > > > --> Where was error supposed to get initialized? > > return error; > >}; > > > > > > > > > > > > > > > > > >BYTE *SetNumber(char Number[1024]) > >{ --> Why allocation of 1024 bytes. The concept of storing the length of --> Number in the first byte, can not span such large an array. > >=09BYTE *CalledPartyNumberStruct =3D new BYTE[1024]; > > > > if (strlen(Number) >=3D 1) > >=09{ --> Here youu will leak the 1024 bytes allocated above > >=09=09int len; > > > >=09=09len =3D strlen(Number); > > > >=09=09/*----- \xLen\x80 STRING '\0' -----*/ > > > >=09=09CalledPartyNumberStruct =3D (unsigned char *)malloc(len + 2 + > >1); > > --> What happens if len > 254? Your single byte for length of overflow. > >=09=09CalledPartyNumberStruct[0] =3D (unsigned char)(len + 1); > >=09=09CalledPartyNumberStruct[1] =3D 0x80; > > > >=09=09strcpy ((char *)&(CalledPartyNumberStruct[2]), Number); ---> Missing else block, to initialize the allocated array. > > }; > > > >=09return CalledPartyNumberStruct; > >}; > > > >-----Urspr=FCngliche Nachricht----- > >Von: Daniel Glenfield [mailto:sp...@ho...] > >Gesendet am: Donnerstag, 24. Oktober 2002 14:14 > >An: Chr...@vo...; dev...@li... > >Betreff: Re: [Dev-C++] Strange phenomenon > > > >Could be a scope problem. You'll need to show us the functions. > > > > > > >From: Christian Wallukat <Chr...@vo...> > > >To: "Dev-Cpp-Users@Lists. Sourceforge. Net (E-Mail)" > > ><dev...@li...> > > >Subject: [Dev-C++] Strange phenomenon > > >Date: Thu, 24 Oct 2002 13:51:23 +0200 > > > > > >Hi List, > > > > > > > > >i have a strange phenomenon in my project: > > > > > >I call a function: Test(char szTest[1024]) with Test("test"); > > > > > >In that function another Function (like the first) will be called: > > >Test2(szTest); > > > > > >the adress of szZest is 0x000000000.... > > > > > >and the content is empty .... > > > > > > > > >Anyone an Idea ???? > > > > > >Kind r > > > > > >Chris > > > > > > > > >------------------------------------------------------- > > >This sf.net email is sponsored by: Influence the future > > >of Java(TM) technology. Join the Java Community > > >Process(SM) (JCP(SM)) program now. > > >http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/jav= avote > > >_______________________________________________ > > >Dev-cpp-users mailing list > > >Dev...@li... > > >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > > >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > >_________________________________________________________________ > >Get a speedy connection with MSN Broadband. Join now! > >http://resourcecenter.msn.com/access/plans/freeactivation.asp >=20 >=20 > _________________________________________________________________ > Internet access plans that fit your lifestyle -- join MSN.=20 > http://resourcecenter.msn.com/access/plans/default.asp >=20 >=20 >=20 > ------------------------------------------------------- > This sf.net email is sponsored by: Influence the future=20 > of Java(TM) technology. Join the Java Community=20 > Process(SM) (JCP(SM)) program now.=20 > http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/javavo= te > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users >=20 |