473,804 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function returns an address that is out of bounds

4 New Member
Hi,

I'm trying to assign variables where vpSec0 points.

Expand|Select|Wrap|Line Numbers
  1. void * vpSec0 = NULL;
  2. CreateHVFESection0(vpSec0);
  3.  
CreateHVFESecti on0 function is below.

Expand|Select|Wrap|Line Numbers
  1. void CreateHVFESection0(void * vpSec0)
  2. {
  3.         int hSec0;      
  4.         size_t * nbytes = (size_t *) malloc(sizeof(size_t));
  5.         hSec0 = bitio_o_open(); 
  6.  
  7.         /* 'B','U','F','R' */
  8.         bitio_o_append(hSec0,66,8);
  9.         bitio_o_append(hSec0,85,8);
  10.         bitio_o_append(hSec0,70,8);
  11.         bitio_o_append(hSec0,82,8);
  12.  
  13.         /* Total length of BUFR message in bytes */
  14.         bitio_o_append(hSec0,0,24);
  15.  
  16.         /* BUFR Edition Number = 4 */
  17.         bitio_o_append(hSec0,4,8);
  18.         vpSec0 = bitio_o_close(hSec0, nbytes);
  19.  
  20.         free(nbytes);
  21.         nbytes = NULL;
  22.  
  23.  
  24. }
  25.  
CreateHVFESecti on0 uses some other functions. But I think the problem is here:
Expand|Select|Wrap|Line Numbers
  1. vpSec0 = bitio_o_close(hSec0, nbytes);
because i run the program with gdb debugger. Before coming here, vpSec0 is 0x0, means NULL. Everything is normal to here.

Expand|Select|Wrap|Line Numbers
  1. void *bitio_o_close (handle, nbytes)
  2.  
  3. int handle;
  4. size_t *nbytes;
  5.  
  6. /* This function closes a output-bitstream identified by HANDLE and returns
  7.    a pointer to the memory-area holding the bit-stream.
  8.  
  9.    parameters:
  10.    HANDLE:  Bit-stream-handle
  11.    NBYTES:  number of bytes in the bitstream.
  12.  
  13.    The funcion returns a pointer to the memory-area holding the bit-stream or
  14.    NULL if an invalid handle was specified. The memory area must be freed by
  15.    the calling function.
  16. */
  17.  
  18. {
  19.  
  20.   if (!bios[handle].used) return NULL;
  21.  
  22. /******* Fill up the last byte with 0-bits */
  23.  
  24.   while (bios[handle].nbits % 8 != 0) bitio_o_append (handle, 0, 1);
  25.  
  26.   *nbytes = (size_t) ((bios[handle].nbits - 1) / 8 + 1);
  27.   bios[handle].used = 0;
  28.   return (void *) bios[handle].buf;
  29. }
  30. void *bitio_o_close (handle, nbytes)
  31.  
  32. int handle;
  33. size_t *nbytes;
  34.  
  35. /* This function closes a output-bitstream identified by HANDLE and returns
  36.    a pointer to the memory-area holding the bit-stream.
  37.  
  38.    parameters:
  39.    HANDLE:  Bit-stream-handle
  40.    NBYTES:  number of bytes in the bitstream.
  41.  
  42.    The funcion returns a pointer to the memory-area holding the bit-stream or
  43.    NULL if an invalid handle was specified. The memory area must be freed by
  44.    the calling function.
  45. */
  46.  
  47. {
  48.  
  49.   if (!bios[handle].used) return NULL;
  50.  
  51. /******* Fill up the last byte with 0-bits */
  52.  
  53.   while (bios[handle].nbits % 8 != 0) bitio_o_append (handle, 0, 1);
  54.  
  55.   *nbytes = (size_t) ((bios[handle].nbits - 1) / 8 + 1);
  56.   bios[handle].used = 0;
  57.   return (void *) bios[handle].buf;
  58. }
  59.  
  60.  
when i step into bitio_o_close function, before
Expand|Select|Wrap|Line Numbers
  1. return (void *) bios[handle].buf
, the address of bios[handle].buf is 0x2a99700930. So we expect that after returning, vpSec0's address will also be 0x2a99700930. But after returning when i print vpSec0, it's address seems 0xffffffff99700 930, and this is out of bounds which falls me in Segmentation faults further in my program.

Please help.
Thanx.
Jul 31 '07 #1
1 2349
weaknessforcats
9,208 Recognized Expert Moderator Expert
Part of your problem is right here:
void CreateHVFESecti on0(void * vpSec0)
{
etc...
Inside this function vpSec0 is a copy of the vpSec0 used to make the call.

C has only call by value so function arguments are always copies of the variables used to call the funciton.

To change the address in the vpSec0 used on the call you need to pass the address of the pointer:

Expand|Select|Wrap|Line Numbers
  1. void CreateHVFESection0(void ** vpSec0)
  2. {
  3. etc...
  4.  
Then inside CreateHVFESecti on0() you change the caller's pointer by:

Expand|Select|Wrap|Line Numbers
  1. *vpSec0 = bitio_o_close(hSec0, nbytes);
  2.  
Jul 31 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2365
by: Randy Jackson | last post by:
I'm attempting to debug some code that uses the System function. When the function is called, it returns Error 1. Does anyone know what that error might be, or where I can find a list of error codes for the function? Any help is most appreciated. -- Randy Jackson http://fourcolorexplosion.com
1
1419
by: Steven T. Hatton | last post by:
If I do: typedef vector<size_t> v_T; pair<v_T, v_T> b_T; b_T bounds(v_T(n), v_T(n)); // if that doesn't work // std::make_pair(v_T(n), v_T(n)); b_T diff_v(n); void populate_bounds(&bounds); // all bounds.first <= bounds.second
6
6300
by: dharmadam | last post by:
Is it possible to pass a column name or the order of the column name in the DB2 table table function. For example, I want to update the address of a person by passing one of the address column name like ZIP CODE or ADDRESS LINE. I will call the function with three parameter--UpdateAddress(5,zip_code,person_id) where 5 indicates ZIP_CODE is the fifth column in the table. If 4 is passed, it indicates the address line is to be updated. ...
8
14010
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on stack. this contains the arguments this function was called with, address to return to after return from this function (the location in the previous stack frame), location of previous frame on stack (base or start of this frame) and local variables...
4
3636
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's useful to help me to solve some basic problem which I may not perceive before. I appreciate your help, sincerely.
17
3265
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ================================================================================ /* A function that returns a pointer-of-arrays to the calling function. */ #include <stdio.h> int *pfunc(void);
5
2642
by: Travis | last post by:
I am using a function that returns a const char * that is usually a word, etc. How can I check to see if what it returns is empty? I tried if (function() == "") and (function() == NULL) and (function() == '/0'). But then I see that the those if statements are flagging true when the function returns back a char * or no length
2
15864
by: sam.barker0 | last post by:
Hi , I am having 3 functions.When I step through when func b returns to funca.it throws an error "cannot find function bounds" funca() { .... ... funcb(); }
7
3906
by: e2point | last post by:
hi, i got a program that is suppose to run 24x7x365. However after functioning for around 15 minutes, it crashes due to a segmentation fault. program is written in c++ and runs in RH Linux 4. When inspected one of the parameters of the crashing frame, i get the following output. NOTE : c1 is a std::vector (gdb) pvector c1
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10359
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9177
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.