An "overpowering odor of marijuana" (as it is defined by my local law enforcement, good to know these things) gives them probable cause to search you, yes. It doesn't sound like they had that though or they would have been able to search the car without asking you.

It sounds like you got away by the skin of your teeth. Probably because it sounds like you really kept your cool well. I'm impressed. So many things could have happened!