I was testing the buffer size of system call, read(), and found a
strange error on Ubuntu 7.10 server. The code is attached.
If the BUFFSIZE is set to from 128 to 255, the code will produce an error as
read error: Success
If the if statement (and the perror) is removed, the error disappears.
I have tried the same program on Sun Solaris 5.10 and got the same results.
The program read from the standard input and write to standard output.
Use any large file as the input redirected to standard input and dump
the output to null.
How to test:
../a.out < AnySufficientLa rgeFile >/dev/null
----------------------------------------
#include <stdio.h>
#include <unistd.h>
#define BUFFSIZE 128
int main(void)
{
char n;
char buf[BUFFSIZE];
while ((n = read(STDIN_FILE NO, buf, BUFFSIZE)) 0)
if (write(STDOUT_F ILENO, buf, n) != n)
perror("write error");
if (n < 0)
perror("read error");
return 0;
}
----------------------------------------- 9 1388
Larry said:
I was testing the buffer size of system call, read(), and found a
strange error on Ubuntu 7.10 server. The code is attached.
Check the return type of read() - I think you'll find that it's not char,
and that fixing it to be the right type will fix your problem.
<snip>
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
"Larry" <la*******@hotm ail.comwrote in message
news:ft******** **@aioe.org...
>I was testing the buffer size of system call, read(), and found a strange error on Ubuntu 7.10 server. The code is attached.
If the BUFFSIZE is set to from 128 to 255, the code will produce an error
as
read error: Success
If the if statement (and the perror) is removed, the error disappears.
Naturally..
char n;
....
if (n < 0)
perror("read error");
return 0;
}
As RH has said, the char n is the problem.
But for this code, n needs to be unsigned, in which case the 'if (n<0)'
should be a compilation error. And if n is signed, it's maximum range seems
to be 127.
--
Bart
On Sun, 13 Apr 2008 10:21:48 +0000, Bartc wrote:
But for this code, n needs to be unsigned, in which case the 'if (n<0)'
should be a compilation error.
Huh? If n is unsigned, it will never be less than zero, but why would
checking that anyway result is a compilation error? What if you're
dealing with a typedef that may be signed or unsigned, depending on the
system, and you want to check that a value is in the range of [0 .. 10]?
It shouldn't be and isn't an error to check
if (n < 0 || n 10) /* handle error */
(This thread was posted to comp.os.linux, but according to my ISP, it
doesn't exist. Newsgroups set to comp.lang.c only.)
"Harald van D?k" <tr*****@gmail. comwrote in message
news:38******** *************** ***@cache4.tilb u1.nb.home.nl.. .
On Sun, 13 Apr 2008 10:21:48 +0000, Bartc wrote:
>But for this code, n needs to be unsigned, in which case the 'if (n<0)' should be a compilation error.
Huh? If n is unsigned, it will never be less than zero, but why would
checking that anyway result is a compilation error?
gcc produces this message:
c:\c>gcc c.c
c.c: In function `main':
c.c:8: warning: comparison is always false due to limited range of data type
Well, OK, it's a warning not an error.
--
Bart
Harald van D?k wrote:
>
.... snip ...
>
(This thread was posted to comp.os.linux, but according to my ISP,
it doesn't exist. Newsgroups set to comp.lang.c only.)
Your ISP is wrong. It probably simply means it doesn't subscribe
to that newsgroup, which is ridiculous, since c.o.l is a principal
group.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
** Posted from http://www.teranews.com **
On Sun, 13 Apr 2008 11:26:26 -0400, CBFalconer wrote:
Harald van D?k wrote:
>>
... snip ...
>> (This thread was posted to comp.os.linux, but according to my ISP, it doesn't exist. Newsgroups set to comp.lang.c only.)
Your ISP is wrong. It probably simply means it doesn't subscribe to
that newsgroup, which is ridiculous, since c.o.l is a principal group.
Are you sure about that? I can access c.o.l.* without problems, but
that's not what this thread was posted to. According to the archives on
Google Groups, there hasn't been any message to c.o.l itself since 2005
either.
Newsgroups reset again, since I can't post otherwise.
Bartc wrote:
"Larry" <la*******@hotm ail.comwrote in message
news:ft******** **@aioe.org...
>>I was testing the buffer size of system call, read(), and found a strange error on Ubuntu 7.10 server. The code is attached.
If the BUFFSIZE is set to from 128 to 255, the code will produce an error as
read error: Success
If the if statement (and the perror) is removed, the error disappears.
Which error? The [apparently] erroneous statement printed, or the error in
your code. Without the 'if()' statment, your code error is still there
(just not so obvious, but could bite you later and you'd be pulling your
hair out trying to track it down - follow RH's advice).
....
>>char n;
...
>>if (n < 0) perror("rea d error"); return 0; }
As RH has said, the char n is the problem.
Not in the if() statement per se (that would depend upon the compiler - see
below).
But for this code, n needs to be unsigned,
Really? My impression is that for that code it /needs/ to be signed.
in which case the 'if (n<0)'
should be a compilation error. And if n is signed, it's maximum range seems
to be 127.
Possibly, depending upon compile options; most compilers I've used will
usually attempt some auto-cast, guessing what the programmer intended.
And then again, the error may, or may not, appear depending upon what the
compiler defines for a 'char'.
"Robert Newson" <Re*******@bull et3.fsnet.oc.ku wrote in message
news:48******** ******@bullet3. fsnet.oc.ku...
Bartc wrote:
>"Larry" <la*******@hotm ail.comwrote in message news:ft******* ***@aioe.org...
>>>I was testing the buffer size of system call, read(), and found a strange error on Ubuntu 7.10 server. The code is attached.
If the BUFFSIZE is set to from 128 to 255, the code will produce an error as
read error: Success
If the if statement (and the perror) is removed, the error disappears.
Which error? The [apparently] erroneous statement printed, or the error
in your code. Without the 'if()' statment, your code error is still there
(just not so obvious, but could bite you later and you'd be pulling your
hair out trying to track it down - follow RH's advice).
...
>>>char n;
...
>>>if (n < 0) perror("re ad error"); return 0; } As RH has said, the char n is the problem.
Not in the if() statement per se (that would depend upon the compiler -
see below).
>But for this code, n needs to be unsigned,
Really? My impression is that for that code it /needs/ to be signed.
Well, if the OP had a pressing reason for using a char type for n, then it
needed to be unsigned to accommodate buffer sizes of 128 to 255. In this
case perhaps the erroneous negative values possibly would be eliminated.
But if those read/write functions could return negative statuses, then
you're right, the OP needs to move up to a wider, signed type.
--
Bart
Harald van D?k wrote:
CBFalconer wrote:
>Harald van D?k wrote:
>>>
... snip ...
>>> (This thread was posted to comp.os.linux, but according to my ISP, it doesn't exist. Newsgroups set to comp.lang.c only.)
Your ISP is wrong. It probably simply means it doesn't subscribe to that newsgroup, which is ridiculous, since c.o.l is a principal group.
Are you sure about that? I can access c.o.l.* without problems,
but that's not what this thread was posted to. According to the
archives on Google Groups, there hasn't been any message to c.o.l
itself since 2005 either.
Newsgroups reset again, since I can't post otherwise.
That (no messages) may well be true, since it seems to be an outer
'containment' group, with about 20 subgroups. My ISP doesn't
complain about the cross-post, but may simply delete it. I know
that posting to non-existent groups produces violent annoyance
messages here.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
** Posted from http://www.teranews.com ** This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Olaf |
last post by:
I have a frameset page witch contains the myFuc() function. The
function is accessed from a page in one of the frames in the frameset.
An example is shown below.
<input onclick="javaScript:alert('document.forms(0)='+document.forms(0));
parent.myFunc(document.forms(0));" type="button" value="Open"
name="Button" ID="Button">
The strange part is that the debug alert says that the
document.forms(0) is an object så all seem to be well. But...
|
by: Neil Ginsberg |
last post by:
I have a strange situation with my Access 2000 database. I have code in the
database which has worked fine for years, and now all of a sudden doesn't
work fine on one or two of my client's machines. The code opens MS Word
through Automation and then opens a particular Word doc. It's still working
fine on most machines; but on one or two of them, the user is getting an
Automation Error. The code used is as follows:
Dim objWord As...
|
by: Kris Vanherck |
last post by:
yesterday i started getting this strange error when i try to run my asp.net
project:
Compiler Error Message: CS0006: Metadata file
'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net
files\spsweb\0e3514bf\cb1844e7\assembly\dl2\3b163f
16\00452d31_84e5c301\infragistics.webui.ultrawebgrid.v3.dll' could not be
found
|
by: Gary |
last post by:
I have an application that has been working just fine for a couple of years.
It queries a SQL database and returns some formatted data back to the client.
I have a new client, who has a larger database than any of our previous
customers. For example, the query to build the datatable now takes about 2
minutes instead of one minute or less. This is a third party database we are
integrating with. He is getting very strange results. For...
|
by: Nathan Sokalski |
last post by:
When I view my index.aspx page any time after the first time, I recieve the
following error:
System.Web.TraceContext.AddNewControl(String id, String parentId, String
type, Int32 viewStateSize) +313
System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
calcViewState) +201
System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
calcViewState) +263
| |
by: ivb |
last post by:
Hi all,
I am using DB2 8.1.11.1 on NT with ASP.NET 1.1
When application make connection to database (via ADO.NET), it set
"Connection timeout" parameter to 30 seconds.
After, when my webpage requests database, and query execution time
exceeds 30 seconds, the following error reported:
===
|
by: Martin Joergensen |
last post by:
Hi,
I've encountered a really, *really*, REALLY strange error :-)
I have a for-loop and after 8 runs I get strange results...... I
mean: A really strange result....
I'm calculating temperatures. T = 20 degrees at all
times.... The 2D T-array looks like this:
|
by: JoReiners |
last post by:
Hello, I have a really strange problem. I'm unable to figure it out on
my own.
I parse very simple xml documents, without any check for their form.
These files look very similar and are encoded in UTF-8.
Now minidom is always able to parse these files with
minidom.parse("file") .
Now when fetching I use this expression:
xmldoc.getElementsByTagName('DocNumb').firstChild.data.encode('latin1')
|
by: Mike C# |
last post by:
Hi all,
I keep getting a strange error and can't pin it down. The message is:
This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.
However I'm not purposely requesting that the Runtime terminate in an
"unusual way." The line that is causing me headaches is:
|
by: Shelly |
last post by:
I am encountering two strange problems.
First one:
I get a "server misconfiguration error", but only sometimes. It occurs on
the first screen that accesses the database on a submit. This error is
intermittent -- sometimes it happens and sometimes not from the same screen
with the same data.
Here is the error:
|
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...
| |
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |