473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Runtime error with C program running Cygwin

Hi to all,

I have written a little Server program in C and I have compiled this
with Cygwin without errors. This is my code:

// Prototype
void wordReceived(int sd,char *s);

int main (unsigned argc, char **argv) {
int SERVER_PORT, sock, client_len, fd;
struct sockaddr_in server, client;
char *theword;
..
.. <OTHER CODE>
..
wordReceived(fd,theword); /* Process the word received from
client*/
..
.. <OTHER CODE>
..
}

void wordReceived(int sd,char *s){
int i=0;
int charRecv = 0;
char c[1];

charRecv = recv(sd, c, 1, 0);
while (c[1] !='\n'){
s[i++]=c[1];
charRecv = recv(sd, c, 1, 0);
} // End while (c !='\n')
s[i]='\0';
}

When the program call wordReceived, Cygwin return to me this message:
"5 [main] myserver 2736 _cygtls:: handle_exception: Error while
dumping state (probably corrupted stack)"
and the program hang.

I have modified my program in this way:

int main (unsigned argc, char **argv) {
int SERVER_PORT, sock, client_len, fd;
struct sockaddr_in server, client;
char theword[30];
char c;
int i, charRecv;
..
.. <OTHER CODE>
..
i=0;
charRecv = recv(fd, &c, 1, 0);
while (c !='\n')
{
theword[i++]=c;
charRecv = recv(fd, &c, 1, 0);
} // End while (c !='\n')
theword[i]='\0';
..
.. <OTHER CODE>
..
}

In this way the program run fine.
Wich is my error in the first program ?
How can modify my code in order to use correctly wordReceived?

I hope in Your help in order to resolve my little problem

Thank You and Best Regards
Nick

May 29 '07 #1
3 6506
On May 29, 1:57 am, nick048 <nicosia.gaet...@moonsoft.itwrote:
Hi to all,

I have written a little Server program in C and I have compiled this
with Cygwin without errors. This is my code:
>
int main (unsigned argc, char **argv) {
int SERVER_PORT, sock, client_len, fd;
struct sockaddr_in server, client;
char *theword;
You declare a char pointer uninitialized
<OTHER CODE>
Do you do something to this pointer in this code?
wordReceived(fd,theword); /* Process the word received from
client*/
You call wordRecieved with theword (as far as I can see,
uninitialized. That is,you give a random address to your function).
void wordReceived(int sd,char *s){
int i=0;
int charRecv = 0;
char c[1];

charRecv = recv(sd, c, 1, 0);
while (c[1] !='\n'){
s[i++]=c[1];
And then you write to this random address, where the program has
probably no right to write.

When the program call wordReceived, Cygwin return to me this message:
"5 [main] myserver 2736 _cygtls:: handle_exception: Error while
dumping state (probably corrupted stack)"
and the program hang.
I don't know cygwin, but I bet that this error means a segmentation
violation.

Cheers,
Quentin.
May 29 '07 #2
nick048 wrote:
charRecv = recv(sd, c, 1, 0);
When the program call wordReceived, Cygwin return to me this message:
"5 [main] myserver 2736 _cygtls:: handle_exception: Error while
dumping state (probably corrupted stack)"
and the program hang.
charRecv = recv(fd, &c, 1, 0);
In this way the program run fine.
What is the prototype for recv and description of parameters?

--
Thad
May 29 '07 #3
nick048 <ni*************@moonsoft.itwrote:
I have written a little Server program in C and I have compiled this
with Cygwin without errors.
I was going to say "turn up the warning level on your compiler", but
I found to my dismay that gcc will accept your original code silently;
perhaps I have merely been coding in Java for too long.
char theword[30];
charRecv = recv(fd, &c, 1, 0);
while (c !='\n')
{
theword[i++]=c;
charRecv = recv(fd, &c, 1, 0);
} // End while (c !='\n')
In this way the program run fine.
Note that it only "runs fine" if you receive 29 characters or less.
If you can't arrange to know how many characters you are going to
receive, you will want to use malloc() and realloc().
Wich is my error in the first program ?
How can modify my code in order to use correctly wordReceived?
I hope in Your help in order to resolve my little problem
Thank You and Best Regards
Nick

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
May 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hal Vaughan | last post by:
I never noticed this before, but when I run an external program through Runtime, like this: Runtime rt = Runtime.getRuntime(); System.out.println("Running external command: " + sCommand); try...
1
by: Will Stuyvesant | last post by:
I never used the popen or popen2 libraries but it is my understanding that they can capture the output of console based programs. Is it also possible to send keystrokes to console base programs? ...
6
by: Steve Holden | last post by:
Does anyone know the workaround for this error, encountered when trying to build PIL 1.1.4 from source under cygwin (Python 2.3.3)? running build_ext building '_imaging' extension gcc...
12
by: Jamie Ruff | last post by:
I am having problems with making system calls on Windows under Cygwin that involve the use of redirection operators and pipes. For example, the line below will cat two files, but the next command...
4
by: KB | last post by:
Hi, I want to write a Python script that controls and automates a Windows GUI computation program. My problem is that I do not know how to quit the Windows GUI program gracefully with a...
17
by: abdur_rab7 | last post by:
Hi, I am compiling code for nanosleep in CYGWIN. During compilation i get the following error Socket.cc: In method `bool Socket::hangOnConnection(int = 0)': Socket.cc:338: aggregate `struct...
0
by: spacelabstudio | last post by:
Hi, I'm observing some weird behavior and have written the following test program to demonstrate. This works under cygwin/WinXP but not Gentoo(kernel 2.6): huh.py...
1
by: edwardzyang | last post by:
I am running Windows XP with cygwin with gcc 3.4.4-1 and gdb 20060706-2. I compiled this very simple program: #include <iostream> using namespace std; int main(int argc, char (*(argv)) ) {...
17
by: Neil | last post by:
A client of mine likes some of the new bells and whistles in Access 2007, and is thinking about converting our A03 format MDB to an A07 format file. However, while some of the users have A07, many...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.