Some cats will attack not the hand that feeds them but the one that pets them. It's often hard to tell whether they really will attack or whether they're just posturing. But the following are signs indicating that they're not just fooling around.
A change in mood: Cats ready for combat show a significant mood change, for example, they'll suddenly appear to be angry or frightened.
Spitting and arching: Cats often spit when they want something, or want someone to stay away. But if they also arch their backs or their fur rises while they're spitting, it means they're going to attack.
A quick flick of the tongue over their lips may show they're becoming agitated.
Ears forward means they're on the offense. Backwards means defence.
Whiskers forward and possibly bristling is also a sign.
A twitching tail or rippling body can show that they want whatever is going on to stop and that they might do something to insure it. The general rule is: the faster the tail is moving, the more agitated they are.
Raised or curled lip. Although this is usually associated with dogs about to attack, it's something to watch out for in cats as well.
If you see any of these signs, especially while you're petting your cat -- watch out.
From 277 Secrets Your Cat Wants You to Know by Paulette Cooper and Paul Noble.