• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Percent Symbol String Bug

Status
Not open for further replies.
Level 5
Joined
Dec 12, 2011
Messages
116
Hey guys, something really weird is happening in my map:

The following code is returning "HP: 100" instead of "HP: 100%" !!
The % symbol simply don't want to appear!

JASS:
function GetNotificationString takes unit u returns string
    local string s = "HP: " + I2S(R2I(GetUnitLifePercent(u))) + "%"
    call BJDebugMsg(s)
    return s
endfunction

Can someone give a clue?

Thanks in advice

hamsterpellet
 
Level 5
Joined
Dec 12, 2011
Messages
116
Nevermind, I found what's the problem!

Just like at the C Programming Language, for example, the percentage symbol is a special char, which is used in different purposes. At the C language, "%d" refers to an integer number.

I don't know for what JASS uses that, but the fact is that I replaced "%" with "%%" and it worked, exactly what I needed.

Thread may be closed!

hamsterpellet
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
I guess it is used for mod ?
JASS does not support that natively. It has to be emulated using integer mathematics.

It might be the way text is printed uses something more like printf rather than puts (the correct way to write a simple string) internally. As such it parses % as a field rather than as a character as that is how C printf works and WC3 is written in C/C++.

Professionally this is called a lack of input sanitization. The same mechanics allows one to execute commands using the preload function. It also is used to hack websites if they make SQL commands from client input text fields.

What should happen is a pre-filter itterates through all characters and replaces all '%' with "%%" thus sanitizing the input.
 
Status
Not open for further replies.
Top