Fread problem

L

Lew Pitcher

Maybe. It should at least provide *some* useful information.

We know that the ugly hack of saving and restoring the contents
of the FILE object avoided the crash. Assuming that the contents
of the FILE object are valid at point A (when they're saved),
and invalid at point B (when they're restored), and that nothing
between points A and B *should* be modifying it, then determining
the earliest point between A and B where the FILE object is actually
modified is likely to tell us something useful.

Of course it's also possible that the code that corrupts the FILE
object does so because something else was corrupted earlier, and
that could be much more difficult to track down.

This is where the difference between a "coder" and a "programmer" becomes
evident.

In my professional life, I've had problems like this one, and a darn sight
less time to solve them than has been experienced here. A good abend dump
(such as a Unix core dump or MVS abend dump), some knowledge of the data
being processed, and the original source code are often the only
information a /programmer/ has to go on. (A /coder/ will, at best, just
code around the problem, and leave the cause of the problem to someone else
to figure out.)

Code analysis tools (such as Valgrind) and code/dump debugging tools (such
as gdb) can give a programmer insight into the root cause of this sort of
error. But, it all comes down to effort; those who won't put the effort
into determining the cause of a problem also won't put much effort into
fixing the problem.
 
E

Eric Sosman

On 7/17/2011 4:45 PM, Jack wrote:
[...]
I sure do understand the point everyone's making, and in an ideal world
I'd get right to the heart of this bug. BUT... the customer pays for
their support contract annually in advance, any time we have to spend on
maintenance from that contract is just a cost to our company, so we get
strong pressure from management to get quick 'n' easy fixes out the door.

Anyways, if the problem reoccurs in future, with any luck it'll end up on
some other maintenance programmer's books not mine. :)

You'll make a fine CEO or politician some day.

"I came up with the quickest, cheapest method I could think of to mask
the symptoms. The problem is still there, but I'll be long gone before
anyone notices, and the next guy will be blamed for it."

A good programmer, however, you are not.

s/good//

Elsethread, this loser complains that "programming jobs don't
grow on trees." Even if they did it's not clear how he'd find them,
situated as he is in the muck at the bottom of a stagnant sewer.
 
C

Cat 22

Jack said:
OK, knock it off guys.

Let me tell you how the world works. Five of our team have lost
their jobs in the last 2 years - thanks a lot, Barack Obama --
working for the elite in Washington and disdaining real America
outside the Beltway.

I have a wife and three kids to keep. Real estate prices round here
have collapsed -- gee, thanks again, Barack -- and the house is now
worth less than our mortgage. If I start to default on my mortgage
payments, we're out on the street. Programming jobs don't grow on
trees. If I lose my job, I'll be defaulting on those payments.

When my boss says he wants customer faults patched up as quickly as
possible and damn the long term effects, I'm going to do exactly
what he says and hope to God it's enough to keep me on the books.

All you people going on with your ideal of programming to
perfection - yeah, I agree with that. But it's not possible for me
where I am right now and there's nothing I can do about that.

Anyways, thanks to everyone who's helped with this problem.
Hmm, moral relativism rears its ugly head, "its not whats right but
whats right for me"
Man! I sure hope you arent working on some kind of life/safety
software! e.g aircraft flight control sw.
Hopefully your just screwing people buying a notepad like editor.
Cat22
 
S

Squeamizh

On 7/17/2011 4:45 PM, Jack wrote:
[...]
I sure do understand the point everyone's making, and in an ideal world
I'd get right to the heart of this bug. BUT... the customer pays for
their support contract annually in advance, any time we have to spend on
maintenance from that contract is just a cost to our company, so we get
strong pressure from management to get quick 'n' easy fixes out the door.
Anyways, if the problem reoccurs in future, with any luck it'll end upon
some other maintenance programmer's books not mine. :)
You'll make a fine CEO or politician some day.
"I came up with the quickest, cheapest method I could think of to mask
the symptoms. The problem is still there, but I'll be long gone before
anyone notices, and the next guy will be blamed for it."
A good programmer, however, you are not.

     s/good//

     Elsethread, this loser complains that "programming jobs don't
grow on trees."  Even if they did it's not clear how he'd find them,
situated as he is in the muck at the bottom of a stagnant sewer.

Well said.
 
J

James Kuyper

On 07/18/2011 04:20 PM, Jack wrote:
....
OK, knock it off guys.

The key thing that I don't think you fully comprehend is just how
short-sighted your non-fix was. It's not going to wait until next year
to come back and bite you - it's the kind of thing that is likely to
come back next week, or next month at the latest. Is your boss really so
short-sighted that he doesn't even care about next month?

The fact that your fix "worked", even in the very limited short-sighted
sense that you're using, implies that something that shouldn't be, is
writing to memory inside of *fp. That's why, by restoring that memory to
its original form, you got fread() to work correctly. However, computer
programs seldom write to memory unless they intend to read from it at
some later time. When the other parts of your program try to read the
values that were written in the wrong location, there's two main
possibilities:

1. They will read it from the correct location.
2. They will read it from the same wrong location that the data was
originally written to, which means that they will read the replacement
data you overwrote it with.

Either way, they will NOT be reading the values that were originally
written to the wrong location. Few programs are likely to work correctly
when the value read from a non-volatile memory location differs from
what was supposed to be written there.

If you were running into this problem during an fclose() call that
happened to be the very last thing your program does, then those issues
wouldn't matter very much. However, a call to fread() is almost always
followed, sooner or later, by more data processing, and something you
haven't even noticed yet is probably already going wrong.

[Political ranting and raving snipped].
When my boss says he wants customer faults patched up as quickly as
possible and damn the long term effects, I'm going to do exactly what he
says and hope to God it's enough to keep me on the books.

Your boss is, ultimately, responsible for such decisions. However, be
very careful how far you go in using that as an excuse for sloppy job
performance. I learned the hard way that just because your boss says
"it's more important to get this out by the deadline, than to get it
correct", doesn't mean that you won't be in trouble if it behaves
incorrectly. I was lucky - my boss at least eventually admitted,
publicly, that he might have forgotten that he gave me such
instructions, and afterwards he was much more cautious about giving me
similar instructions. I don't think you can count on your boss being so
honest about it.

At the very least, get such instructions in writing from your boss. If
he won't commit them to writing, write down what he's said yourself and
send it to him, asking for confirmation in writing. If he refuses, you
can reasonably assume that what he's afraid to leave documentary
evidence that he gave you such orders, which is generally a very bad
sign. He'll almost certainly blame the resulting problems on you when it
comes time to pay the piper. That means that you'll be the first out the
door when the next round of layoffs come.

Even if you get it in writing, that might not be enough to save your
job. Every time you take such a short-cut to save time now, someone will
pay for it in the future, even if your boss wants to deny the existence
of that future, and that someone might be you.
All you people going on with your ideal of programming to perfection -
yeah, I agree with that. But it's not possible for me where I am right
now and there's nothing I can do about that.

The idea that there's nothing you can do about this is a self-fulfilling
prophecy. I'd recommend that you start preparing immediately to search
for a new job. Even if you don't get blamed for the problems caused by
obeying your boss's instructions, if his attitudes are typical of the
management of your company, then it's likely to go out of business soon.
Since you'll need to start your job search soon, anyway, why not search
for a company with a better attitude towards product quality?
 
S

Stephen Sprunk

Let me tell you how the world works. Five of our team have lost their
jobs in the last 2 years ...

When my boss says he wants customer faults patched up as quickly as
possible and damn the long term effects, I'm going to do exactly what he
says and hope to God it's enough to keep me on the books.

Have you not considered that such a short-sighted outlook and resulting
poor customer service is likely _why_ your company is laying off
employees? My employer has been on a hiring spree for the last several
years, and we're raking in record profits. How do we do that in a bad
economy? By making products that are /higher quality/ than our
competitors and offering great customer service. We don't kludge around
problems; we /fix/ them.
All you people going on with your ideal of programming to perfection -
yeah, I agree with that. But it's not possible for me where I am right
now and there's nothing I can do about that.

With that attitude, no, there's probably not; I sure as heck wouldn't
want to hire you.
Anyways, thanks to everyone who's helped with this problem.

The best thanks would be to not ignoring their advice.
... thanks a lot, Barack Obama -- working for the elite in Washington
and disdaining real America outside the Beltway. ...

If you want to post political diatribes, there are plenty of newsgroups
for that. It's off-topic here, though.

S
 
B

blmblm

[...]
Thanks for your help. I think I've now found a solution.

After the file is first Fopen'd, I make a backup of the internal buffers.
fp=Fopen(...);
FILE fback;
memcpy(&fback,fp,sizeof(FILE));

then before the fread I restore this buffer,
memcpy(fp,&fback,sizeof(FILE));
Fread(...,fp);

Now there is no segmentation fault, job done.

When your smoke alarm jolts you awake in the middle of the
night, do you fix the problem by stuffing cotton in your ears
and going back to sleep?

When the BRAKE TROUBLE light on your car's dashboard refuses
to go out, do you put a piece of tape over it?

I actually heard a story a while back about a group of people
doing something very similar. I'm not remembering details now
(and that bugs me), but possibly it had to do with a red light on
their phones that indicated voice mail and them taping over it.
 
B

blmblm

[ snip ]

[ snip ]
I sure do understand the point everyone's making, and in an ideal world
I'd get right to the heart of this bug. BUT... the customer pays for
their support contract annually in advance, any time we have to spend on
maintenance from that contract is just a cost to our company, so we get
strong pressure from management to get quick 'n' easy fixes out the door.

Anyways, if the problem reoccurs in future, with any luck it'll end up on
some other maintenance programmer's books not mine. :)

One wonders how/whether your "fix" will complicate the job of that
other maintenance programmer. At least you put in a comment, right?
though really, it might be tricky to word a comment in a way that
would be helpful to other programmers without being something you
would not want repeated to your boss.

I've been a maintenance programmer, and it's likely that in that
capacity I came up with my share of ugly hacks (hard to remember
given that it was many years ago), but this one is -- memorable.
 
B

blmblm

That's actually a reasonable first step in tracking down the real
problem.

If I were working on this, I might do the following.

First, change Fopen and Fread to fopen and fread, respectively.

I'm mildly curious about that (why the capital letters) myself.

I'm speculating that perhaps the original code used fopen and fread,
but somehow between there and the newsgroup post some tool that
"helps" by capitalizing letters was involved. I'm reminded of
the occasion, some years ago, when I received code from a student
in the form of a Word document (which apparently had been created
with all Word's default auto-correct stuff turned on). You can
all probably imagine ....

Maybe the OP will explain. Or not, given the direction of subsequent
discussion.

[ snip ]
 
B

blmblm

/*
* The following line was added to hide a memory corruption bug.
* The boss says "do something ASAP to make the customer think that
* it's fixed, even if it really makes things worse". I know that
* this isn't a fix, in any sense of the word, but this is the only
* thing I can come up with that will let me keep my job. (At least
* for now.)
*
* P.S. Good thing we don't use any version control software, so I
* don't have to check in this comment under my name.
*/

:)? But not really, maybe.
But, would you remember _why_ you did it?

Probably not unless I recorded the "why" somewhere. Which, at
that long-ago job, I probably would have done, because my immediate
supervisor was a reasonable and technically competent person. If
that hadn't been the case -- I don't know.

(For what it's worth, the only ugly-hack fix I remember from that
job was not mine, but a colleague's, and while I can remember more
or less *what* he did, my recollection of the *why* is dimmer.
We're drifting further and further OT here so maybe I should leave
it at that.)
 
E

Eric Sosman

[...]
When the BRAKE TROUBLE light on your car's dashboard refuses
to go out, do you put a piece of tape over it?

I actually heard a story a while back about a group of people
doing something very similar. I'm not remembering details now
(and that bugs me), but possibly it had to do with a red light on
their phones that indicated voice mail and them taping over it.

Every now and again the "Car Talk" guys Tom and Ray Magliozzi,
better known as "Click and Clack, the Tappet Brothers," recommend
to a caller that he or she cover an annoying dashboard light with
a piece of Official Car Talk Black Tape. They then usually offer
to sell the said tape for a mere umpteen bucks, plus shipping.

I've never heard them take this stance with a brake warning light.
 
S

Seebs

Every now and again the "Car Talk" guys Tom and Ray Magliozzi,
better known as "Click and Clack, the Tappet Brothers," recommend
to a caller that he or she cover an annoying dashboard light with
a piece of Official Car Talk Black Tape. They then usually offer
to sell the said tape for a mere umpteen bucks, plus shipping.
I've never heard them take this stance with a brake warning light.

I haven't heard them do it, but!

We have a 1994 Subaru where the "ABS" (Antilock Brake System) light comes
on after about 30 seconds of driving. Every time. The brakes work fine.
We have had three sets of mechanics look at that light. For various reasons,
it is effectively impossible to extract a diagnostic code from the vehicle
(the terminals that are supposed to report it, and the lights, are physically
MISSING on this particular car!), and mostly they spend an hour or three
studying it, checking things out, and so on, and then inform us that:

1. It may or may not be serious.
2. Everything appears to be in good working order.
3. Even if the ABS fails, the regular brakes are fully independent and
should be fine.
4. You might as well ignore it.

So it DOES happen.

Similarly, while in principle a segmentation fault is a Very Serious Thing,
we have a standard procedure that if a *build* segfaults, and then never
does it again on any machine, we disregard that. We do enough builds on
enough hardware that we do have a non-zero incidence rate of "apparently a
bit got flipped".

-s
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top