Skip to contentSkip to conversation

lp: too large subtraction on unsigned?

DISCUSSION Roel Kluin 2 participants 2 messages Mar 1, 2009

lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

vi drivers/char/lp.c +705

note that count is unsigned, and we do the loop:

do {
	if (canwrite > 0) {
		...
		count -= written;
	}
	if (lf && canwrite <= 0) {
		...
		count--;
		...
	}
} while (count > 0 && (CONSOLE_LP_STRICT || written > 0));

Isn't this wrong?

Roel

#1 lore raw

Doesn't look like something is wrong, or I'm missing something... :

Quoted 5 lines

do {
       if (canwrite > 0) {
               ...
               count -= written;
       }

If there are chars left you write to the PP and take it out of the total

Quoted 6 lines

       if (lf && canwrite <= 0) {
               ...
               count--;
               ...
       }
} while (count > 0 && (CONSOLE_LP_STRICT || written > 0));

The second if is for translating \n to \r\n only if you've already written everything (up to /n) to the PP

If count > 0 fails (that is, count == 0) you get out of the loop

Signature · 2 lines
-
Thiago Galesi