If, for example, I plan for a character to die in the middle of the story, and let's say I'd like to foreshadow his death by dropping a few hints here and there, what should I avoid when dropping hints about the approaching death?
Think about the purpose and effect of foreshadowing. If you are walking home and you see a column of smoke rising over your neighbourhood, you will probably rush forward with a lump in your throat fearing that you house is on fire. But when you turn the corner and see your house in flames, you will probably stop dead in your tracks, at least for a moment. Which of these effects do you want to have on your reader?
If you want to them to rush forward, if you want to put a lump in their throat, you must strongly suggest the possibility while leaving some ambiguity.
If you want to stop them dead in their tracks, you confront them with the reality.
Hinting the possibility of the death will have one effect. Hinting the certainty of it will have the other.
I've heard it said that the ideal ending to a book is completely expected and completely surprising to the reader at the same time. The reader needs to be placed in a mode where the end will seem exactly right, and emotionally truthful, and believable, and yet also it needs to seem fresh and astonishing. Obviously it's a tough balancing act, which is why so many writers find the end of the book the hardest part to write.
Foreshadowing is a tool to build that effect at the end. You don't want the reader to feel completely blindsided and betrayed by a character's death, but you also don't want it to be expected, so you create a subtle sense of doom, hopefully quiet enough to pass unnoticed by the reader until later. What you want to avoid is hitting the reader over the head with something that needs to still register as a surprise.
Some ways of foreshadowing are to make the character particularly frail, or often sick, or (conversely) reckless and brave/foolhardy. Having those traits (in real life or fiction) doesn't necessarily mean a character is doomed, but it does make us worry a little more about him or her. If you have a first person narrator, they can also speak of the person in an elegiac manner (as in the opening to The Great Gatsby). It's also possible to use a little indirection. In The Fault In Our Stars, the main characters are all critically ill, but who lives and who dies is not necessarily who the reader is initially led to expect.
I can think of several instances of bad foreshadowing, where I have moved from thinking the character might die, to knowing beyond any doubt that he will die. Let's examine them first:
In Farscape (TV series), a "good" character crossed a moral event horizon - he did something so completely terrible, that the only redemption possible for him was a heroic death.
Talyn, a baby spaceship, has been growing increasingly paranoic, until he shot and destroyed a hospital ship, killing everyone on board.
In Dawnton Abbey, a character was in the way for a very obvious love pairing. Clearly, she had to go. As she was good and loving etc., the only way left open to her to go was death.
Lavinia was in the way for MCs Matthew and Mary, whose marriage was foreshadowed from the first episode of the first season. She conveniently died of the flu.
In Jim Butcher's Dresden Files, the foreshadowing was proper foreshadowing, no other tropes getting mixed in as in previous examples. However, there was just too much of it. [MAJOR spoiler ahead]
In Changes, Harry's office gets permanently destroyed, his car gets permanently destroyed, his house gets permanently destroyed. In all cases, the permanence is emphasised. I think he actually talks about the car getting "killed". If that's not enough, another character addresses him with "O Captain my captain". Guess what happens in the end?
In all those cases, I have moved from the edge-of-my-seat, lump-at-my-throat fear that @MarkBaker describes, to being bored with every new bit of foreshadowing, or "maybe they will not die" that the writers attempted to throw at me - I already knew where things were going, everything else was redundant.
Now, how can this be avoided?
First, don't overdo it. Avoid obvious death-tropes, like the ones I showed above and the ones @DeauX.Machinus mentions.
If you use an omniscient narrator, you can show the forces amassing against the character: if he chooses to do "some particular thing", he will most likely die. But he might not choose to do it, right? Even if he's likely to. You create anticipation and dread.
Alexandre Dumas does it masterfully in La Dame de Monsoreau:
There's an ambush being prepared for Bussy in Diane's house. But he's offered warnings, good reasons, and even explicit orders not to go there that night. So maybe he won't go?
Once he's there, there's the ambush, but Bussy has been established as an almost super-human fencer. So maybe he can win this time too?
Once it's clear he's not going to win this time, we know help is on the way, so maybe they will arrive on time?
You can set up from the beginning that everyone can die - no character wears plot armour. Remarque in All Quiet on the Western Front doesn't need to foreshadow every single death: he establishes it early on that this is war, people are going to die. Each following death is foreshadowed by the previous ones. Similarly, G.R.R. Martin in Song of Ice and Fire only needs a character to make a bad decision, for us to start fearing he'll pay for it. To use @MarkBaker's metaphor, the bad decision serves as the smoke rising in the distance.
Basically, if something has happened in a story once, it can happen again: one character died in a war, so can another. If something almost happened, it can happen: one character almost got run over by a car, another might be killed in a car accident later. If a process starts, it can continue to its natural end: a character falls ill, he can die. If a danger is shown, it can be realised: a gun on the wall in the first act.
What death would feel out of the blue?
A death caused by a character acting "out of character": someone who never showed the slightest hint of depression suddenly committing suicide, a character who is afraid of heights dying in a paragliding accident, etc.
A death that is random, not related to the plot established so far: blue ice falling on a person, a character whom we haven't seen pregnant suddenly dying in childbirth, a character getting caught in the crossfire of a shootout between criminals, where criminals haven't been mentioned to exist.
A death that runs contrary to previous foreshadowing. If a character is told by an oracle that they have a great destiny, you don't expect them to die in a random skirmish in the next chapter.
Foreshadowing that looks like foreshadowing is poorly-executed foreshadowing.
You can leave clues in the narrative which in retrospect point to the events that follow, but these should be things the characters naturally see.
You prepare the reader for the discovery of Susan's untimely demise by saying that Brian was worried because he had not heard from Susan in three weeks.
You do not do this by ending a chapter with the phrase, "Brian was soon to regret letting Susan stay in the cabin by herself."
You don't make him mention death eg "someday, you'll be the death of me..." Eg Star Wars
You don't make him show pictures of home to his buddies. This is a DEAD giveaway (excuse my pun), especially in military fic.
You might want to weave in a death theme (Eg gladiator) which doesn't really foreshadow anything until it's too late-- the end of the story. Or in your case-- the middle.
You also might want to check out Writing Excuses episode 9.49: Hiding the Open Grave. It is basically what I said, only with more elaboration. You might find it useful to refer to while writing your book.
Tell us how it goes!