[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: When reading from a serialport read returns a Bad Address/EFAULT err
From: |
Paul Pluzhnikov |
Subject: |
Re: When reading from a serialport read returns a Bad Address/EFAULT error |
Date: |
01 Nov 2004 15:45:37 -0800 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Artificial Intelligence) |
tlann@technoeclectic.com writes:
> When I'm trying to read from a serial port configured as 9600baud 081 I
> get a EFAULT/Bad address error.
Your problem has nothing whatsoever to do with serial port.
> unsigned char* SerialPort::rcvChar(int bytestoread)
> {
> unsigned char* temp;
> if (read(m_iFd, temp, bytestoread) < 0)
Reading butes into memory, pointed at by *uninitialized* pointer,
is a bad idea (TM).
The obvious correction is something like this:
unsigned char* SerialPort::rcvChar(int bytestoread)
{
unsigned char temp[bytestoread]; // note: gcc extension
if (read(m_iFd, temp, bytestoread) < 0)
and this will cure the EFAULT, but will not produce correct results
upon return. Why that is so is left as an exercise for the reader.
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: When reading from a serialport read returns a Bad Address/EFAULT error,
Paul Pluzhnikov <=