I suggest you use 普通话. It is 100% safe though it's not always accurate.
普通话 Vs 汉语/中文
In fact,we call 'spoken Mandarin' 普通话,emphasizing that it is standard officially ,widely spread and it's the only received pronunciation of Mandarin/Chinese,not any dialect. So when I talk to another Chinese person about accents or dialects, I use '普通话' to express Mandarin. It is absolutely polite. Like,"我普通话不好,前后鼻音不分“/”我只会讲普通话,不会方言“
汉语or 中文 underlines that Mandarin/Chinese is not a foreign language (for China ),unlike English or Korean.
A Chinese person who is learning Mandarin is learning 普通话; A foreigner who is learning Mandarin is usually called '学汉语/中文'.
汉语 Vs 中文
It is true that 中文 looks like 'Chinese (written) language' while 汉语 looks like '汉/Han (spoken)language'. But the thing is to be accurate,Mandarin is not 汉's language. It was a dialect used in North China in the first place, largely effected by Machu language.
I am a 汉 person grew up in a southern city whose local dialect is quite different. Mandarin is one of my mother tongues and I speak Mandarin much more frequently and fluently.But it is, um, not really MY language considering the great differences in climate, custom and culture between north and south.But no, it is not offensive to call Mandarin '汉语' when speaking with me,as if it is the only spoken language for 汉 descent.
When you talk with non-汉 Chinese (少数民族) ,it maybe not polite to emphasize on their descent with '汉语'.But it's also true that some of them learn Mandarin as a second language, in which case using 中文 make them sounds non-Chinese.
So just use 普通话 in all situations if you want to avoid offence.