Help Needed With Understanding Statement in E-SQL
Posted in 2006
Topics: Installation, Setup & Upgrades, SQL Development & Query Writing, Connectivity: ESQL/C, 4GL & Embedded SQL, Platform-Specific Issues
Informix 9.21.UC5XF, AIX 4.3.3 (Yes, I know, trying to get them upgraded to 9.40.) Please assist me with understanding why this error is happening. One of the company's prior programmers designed the program to catch a specific error; however, I am trying to find out what would cause the error to occur. Here is a snippet of the program: Initialization: #include <malloc.h>#include <memory.h>#include "decimal.h"#include "datetime.h" extern void fgl_fatal(const char *, int, int);extern void popint(int *); $static struct TEMPLATE { long cnt[100]; decimal(17,4) dec[100]; decimal(15,4) pri[100];}; $extern struct TEMPLATE g_cust;$static struct TEMPLATE *ptr; Section of the program I am concerned with: s_g_cust_dynamicarray(int arg){ int size; if (arg != 1) fgl_fatal("g_cust.ec", 84, -1318); popint(&size); if (!(ptr = (struct TEMPLATE *)realloc((void *)ptr, (size_t)((size + 1)* sizeof(struct TEMPLATE ))))) fgl_fatal("g_cust.ec", 88, -1319); return(0);}The error I am trying to interpret is the one denoted by the -1319 error, which equates to the following: The 4GL program has run out of runtime data space memory.Would some mind interpreting what is causing the problem? What kind of memory is it running out of? Do I need to increase SHMVIRTSIZE? Its current settings are: SHMVIRTSIZE 524288 # initial virtual shared memory segment sizeSHMADD 65536 # Size of new shared memory segments (Kbytes) I appreciate any and all time anyone spends on this. My C is quite rusty and I need some help on this quick as the program is used at the end of each month and they need to run it for this past month and at the end of this month ... which is soon !!! Thank you in advance.Clifton Bean _______________________________________________ Join Excite! - http://www.excite.com The most personalized portal on the Web!
On 2/17/06, clifbean@ex.... <clifbean@excite.com> wrote: > Informix 9.21.UC5XF, AIX 4.3.3 (Yes, I know, trying to get them upgraded to > 9.40.) Please assist me with understanding why this error is happening. One of > the company's prior programmers designed the program to catch a specific > error; however, I am trying to find out what would cause the error to occur. > Here is a snippet of the program: Initialization: #include > <malloc.h>#include <memory.h>#include "decimal.h"#include > "datetime.h" extern void fgl_fatal(const char *, int, int);extern void > popint(int *); $static struct TEMPLATE { long cnt[100]; decimal(17,4) > dec[100]; decimal(15,4) pri[100];}; $extern struct TEMPLATE g_cust;$static > struct TEMPLATE *ptr; Section of the program I am concerned with: > s_g_cust_dynamicarray(int arg){ int size; if (arg != 1) fgl_fatal("g_cust.ec", > 84, -1318); popint(&size); if (!(ptr = (struct TEMPLATE *)realloc((void > *)ptr, (size_t)((size + 1)* > sizeof(struct TEMPLATE ))))) fgl_fatal("g_cust.ec", 88, -1319); return(0);}The > error I am trying to interpret is the one denoted by the -1319 error, which > equates to the following: The 4GL program has run out of runtime data space > memory.Would some mind interpreting what is causing the problem? What kind of > memory is it running out of? Do I need to increase SHMVIRTSIZE? Its current > settings are: SHMVIRTSIZE 524288 # initial virtual shared memory segment > sizeSHMADD 65536 # Size of new shared memory segments (Kbytes) I appreciate > any and all time anyone spends on this. My C is quite rusty and I need some > help on this quick as the program is used at the end of each month and they > need to run it for this past month and at the end of this month ... which is > soon !!! Thank you in advance.Clifton Bean The C code is quite inscrutable as posted: #include <malloc.h> #include <memory.h> #include "decimal.h" #include "datetime.h" extern void fgl_fatal(const char *, int, int); extern void popint(int *); $static struct TEMPLATE { long cnt[100]; decimal(17,4) dec[100]; decimal(15,4) pri[100];}; $extern struct TEMPLATE g_cust; $static struct TEMPLATE *ptr; Section of the program I am concerned with: s_g_cust_dynamicarray(int arg) { int size; if (arg != 1) fgl_fatal("g_cust.ec", 84, -1318); popint(&size); if (!(ptr = (struct TEMPLATE *)realloc((void *)ptr, (size_t)((size + 1)*sizeof(struct TEMPLATE ))))) fgl_fatal("g_cust.ec", 88, -1319); return(0); } OK - the error -1319 here means that the realloc() failed. This could be for any number of reasons. There is no validation on the size passed via the I4GL stack, so if size is zero, or negative, there is ample opportunity for things to go horribly wrong. In general, you should validate your arguments a little more. I'd introduce a size_t variable to compute the second argument to realloc, and validate that computation (did I really want more than 100 MB allocated?) and then you can simplify that if condition. The $static in front of the structure type definition is not usual; I would remove the keyword static. I'm not sure whether you need the $ in front of those variables - it depends on whether you pass any of them to SQL statements. Your structures are about 2400 bytes long; how large a number do you pass to s_g_cust_dynamicarray? Did you know that I4GL 7.32 has dynamic arrays in the language? SHMVIRTSIZE and SHMADD are not material in I4GL programs - they affect IDS, not I4GL. You might need to tinker with the shared memory address where your communications data segment is loaded - if you use shared memory connections. Otherwise, it appears you have some memory leak. Your code needs to be upgraded to use "fglsys.h" to declare popint() and fgl_fatal(); you must still be using an I4GL version prior to 7.31 because as written, it would not work with 7.31 or 7.32. Removing the declarations for fgl_fatal() and popint() and adding '#include "fglsys.h"' will allow it to work OK. I'm not convinced you need <malloc.h>; you should normally use <stdlib.h> to declare malloc, realloc, et al. You should explicitly declare the function to return int - C99 bans the use of 'implicit int' declarations. -- Jonathan Leffler #include <disclaimer.h> Email: jleffler@earthlink.net, jleffler@us.ibm.com Guardian of DBD::Informix v2005.02 -- http://dbi.perl.org/
Thank you, Jonathan, for re-adding the CR/LFs to the email. I did not know that the excite email engine would remove the formatting the message originally had when I wrote it. Yes, we are using I4GL 7.30.UC7 and yes the program was written to generate a dynamic array. We are in the midst of having one of our clients perform an upgrade and we plan to upgrade the 4GL to 7.32 at that time.I am just trying to patch this program and keep it usable until we can get there. We will then modify the programs using this E-SQL program. Thanks for your help once again. I am going to try your suggested modifications and hope it will allow the program to continue being used until that time (this upcoming summer is being discussed). Take care.Clifton (PS. Crossing fingers this is not reformatted as well ....)--- On Sat 02/18, Jonathan Le.... < jleffler.iiug@gmail.com > wrote:From: Jonathan Le.... [mailto: jleffler.iiug@gmail.com]To: ids@iiug.orgDate: Sat, 18 Feb 2006 13:33:01 -0500 (EST)Subject: Re: Help Needed With Understanding Statement i.... [6433]On 2/17/06, clifbean@ex.... wrote: > Informix 9.21.UC5XF, AIX 4.3.3 (Yes, I know, trying to get them upgraded to > 9.40.) Please assist me with understanding why this error is happening. One of > the company's prior programmers designed the program to catch a specific > error; however, I am trying to find out what would cause the error to occur. > Here is a snippet of the program: Initialization: #include > &lt;malloc.h&gt;#include &lt;memory.h&gt;#include "decimal.h"#include > "datetime.h" extern void fgl_fatal(const char *, int, int);extern void > popint(int *); $static struct TEMPLATE { long cnt[100]; decimal(17,4) > dec[100]; decimal(15,4) pri[100];}; $extern struct TEMPLATE g_cust;$static > struct TEMPLATE *ptr; Section of the program I am concerned with: > s_g_cust_dynamicarray(int arg){ int size; if (arg != 1) fgl_fatal("g_cust.ec", > 84, -1318); popint(&amp;size); if (!(ptr = (struct TEMPLATE *)realloc((void > *)ptr, (size_t)((size + 1)* > sizeof(struct TEMPLATE ))))) fgl_fatal("g_cust.ec", 88, -1319); return(0);}The > error I am trying to interpret is the one denoted by the -1319 error, which > equates to the following: The 4GL program has run out of runtime data space > memory.Would some mind interpreting what is causing the problem? What kind of > memory is it running out of? Do I need to increase SHMVIRTSIZE? Its current > settings are: SHMVIRTSIZE 524288 # initial virtual shared memory segment > sizeSHMADD 65536 # Size of new shared memory segments (Kbytes) I appreciate > any and all time anyone spends on this. My C is quite rusty and I need some > help on this quick as the program is used at the end of each month and they > need to run it for this past month and at the end of this month ... which is > soon !!! Thank you in advance.Clifton Bean The C code is quite inscrutable as posted: #include #include #include "decimal.h" #include "datetime.h" extern void fgl_fatal(const char *, int, int); extern void popint(int *); $static struct TEMPLATE { long cnt[100]; decimal(17,4) dec[100]; decimal(15,4) pri[100];}; $extern struct TEMPLATE g_cust; $static struct TEMPLATE *ptr; Section of the program I am concerned with: s_g_cust_dynamicarray(int arg) { int size; if (arg != 1) fgl_fatal("g_cust.ec", 84, -1318); popint(&size); if (!(ptr = (struct TEMPLATE *)realloc((void *)ptr, (size_t)((size + 1)*sizeof(struct TEMPLATE ))))) fgl_fatal("g_cust.ec", 88, -1319); return(0); } OK - the error -1319 here means that the realloc() failed. This could be for any number of reasons. There is no validation on the size passed via the I4GL stack, so if size is zero, or negative, there is ample opportunity for things to go horribly wrong. In general, you should validate your arguments a little more. I'd introduce a size_t variable to compute the second argument to realloc, and validate that computation (did I really want more than 100 MB allocated?) and then you can simplify that if condition. The $static in front of the structure type definition is not usual; I would remove the keyword static. I'm not sure whether you need the $ in front of those variables - it depends on whether you pass any of them to SQL statements. Your structures are about 2400 bytes long; how large a number do you pass to s_g_cust_dynamicarray? Did you know that I4GL 7.32 has dynamic arrays in the language? SHMVIRTSIZE and SHMADD are not material in I4GL programs - they affect IDS, not I4GL. You might need to tinker with the shared memory address where your communications data segment is loaded - if you use shared memory connections. Otherwise, it appears you have some memory leak. Your code needs to be upgraded to use "fglsys.h" to declare popint() and fgl_fatal(); you must still be using an I4GL version prior to 7.31 because as written, it would not work with 7.31 or 7.32. Removing the declarations for fgl_fatal() and popint() and adding '#include "fglsys.h"' will allow it to work OK. I'm not convinced you need ; you should normally use to declare malloc, realloc, et al. You should explicitly declare the function to return int - C99 bans the use of 'implicit int' declarations. -- Jonathan Leffler #include Email: jleffler@earthlink.net, jleffler@us.ibm.com Guardian of DBD::Informix v2005.02 -- http://dbi.perl.org/ ******************************************************************************* Forum Note: Use "Reply" to post a response in the discussion forum. _______________________________________________ Join Excite! - http://www.excite.com The most personalized portal on the Web!