Skip to content

Commit

Permalink
Use bitwise OR instead of addition
Browse files Browse the repository at this point in the history
  • Loading branch information
AtariDreams committed Jan 23, 2023
1 parent 6389058 commit a521b23
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 49 deletions.
8 changes: 4 additions & 4 deletions backend/usb-libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ get_device_id(usb_printer_t *printer, /* I - Printer */
char *buffer, /* I - String buffer */
size_t bufsize) /* I - Number of bytes in buffer */
{
int length; /* Length of device ID */
size_t length; /* Length of device ID */


if (libusb_control_transfer(printer->handle,
Expand All @@ -1065,7 +1065,7 @@ get_device_id(usb_printer_t *printer, /* I - Printer */
* bytes. The 1284 spec says the length is stored MSB first...
*/

length = (int)((((unsigned)buffer[0] & 255) << 8) | ((unsigned)buffer[1] & 255));
length = (((unsigned)buffer[0] & 255) << 8) | ((unsigned)buffer[1] & 255);

/*
* Check to see if the length is larger than our buffer or less than 14 bytes
Expand All @@ -1076,7 +1076,7 @@ get_device_id(usb_printer_t *printer, /* I - Printer */
*/

if (length > bufsize || length < 14)
length = (int)((((unsigned)buffer[1] & 255) << 8) | ((unsigned)buffer[0] & 255));
length = (((unsigned)buffer[1] & 255) << 8) | ((unsigned)buffer[0] & 255);

if (length > bufsize)
length = bufsize;
Expand All @@ -1098,7 +1098,7 @@ get_device_id(usb_printer_t *printer, /* I - Printer */
* nul-terminate.
*/

memmove(buffer, buffer + 2, (size_t)length);
memmove(buffer, buffer + 2, length);
buffer[length] = '\0';

return (0);
Expand Down
3 changes: 1 addition & 2 deletions cups/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2513,8 +2513,7 @@ cups_fill(cups_file_t *fp) /* I - CUPS file */
}
}

tcrc = ((((((uLong)trailer[3] << 8) | (uLong)trailer[2]) << 8) |
(uLong)trailer[1]) << 8) | (uLong)trailer[0];
tcrc = ((uLong)trailer[3] << 24) | ((uLong)trailer[2] << 16) | ((uLong)trailer[1] << 8) | ((uLong)trailer[0]);

if (tcrc != fp->crc)
{
Expand Down
4 changes: 1 addition & 3 deletions cups/http-addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,7 @@ httpGetHostByName(const char *name) /* I - Hostname or IP address */
if (ip[0] > 255 || ip[1] > 255 || ip[2] > 255 || ip[3] > 255)
return (NULL); /* Invalid byte ranges! */

cg->ip_addr = htonl((((((((unsigned)ip[0] << 8) | (unsigned)ip[1]) << 8) |
(unsigned)ip[2]) << 8) |
(unsigned)ip[3]));
cg->ip_addr = htonl((ip[0] << 24) | (ip[1] << 16) | (ip[2] << 8) | ip[3]);

/*
* Fill in the host entry and return it...
Expand Down
5 changes: 1 addition & 4 deletions cups/http-addrlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,7 @@ httpAddrGetList(const char *hostname, /* I - Hostname, IP address, or NULL for p
return (NULL);

first->addr.ipv4.sin_family = AF_INET;
first->addr.ipv4.sin_addr.s_addr = htonl((((((((unsigned)ip[0] << 8) |
(unsigned)ip[1]) << 8) |
(unsigned)ip[2]) << 8) |
(unsigned)ip[3]));
first->addr.ipv4.sin_addr.s_addr = htonl((ip[0] << 24) | (ip[1] << 16) | (ip[2] << 8) | ip[3]);
first->addr.ipv4.sin_port = htons(portnum);
}
}
Expand Down
6 changes: 3 additions & 3 deletions cups/http-support.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ httpEncode64_2(char *out, /* I - String to write to */
if (inlen > 1)
*outptr ++ = base64[(((in[0] & 255) << 4) | ((in[1] & 255) >> 4)) & 63];
else
*outptr ++ = base64[((in[0] & 255) << 4) & 63];
*outptr ++ = base64[(in[0] << 4) & 63];
}

in ++;
Expand All @@ -746,9 +746,9 @@ httpEncode64_2(char *out, /* I - String to write to */
if (outptr < outend)
{
if (inlen > 1)
*outptr ++ = base64[(((in[0] & 255) << 2) | ((in[1] & 255) >> 6)) & 63];
*outptr ++ = base64[((in[0] << 2) | (in[1] >> 6)) & 63];
else
*outptr ++ = base64[((in[0] & 255) << 2) & 63];
*outptr ++ = base64[(in[0] << 2) & 63];
}

in ++;
Expand Down
2 changes: 1 addition & 1 deletion cups/ipp-support.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ ippAttributeString(
{
unsigned year; /* Year */

year = ((unsigned)val->date[0] << 8) + (unsigned)val->date[1];
year = ((unsigned)val->date[0] << 8) | (unsigned)val->date[1];

if (val->date[9] == 0 && val->date[10] == 0)
snprintf(temp, sizeof(temp), "%04u-%02u-%02uT%02u:%02u:%02uZ",
Expand Down
30 changes: 9 additions & 21 deletions cups/ipp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2910,9 +2910,8 @@ ippReadIO(void *src, /* I - Data source */

ipp->request.any.version[0] = buffer[0];
ipp->request.any.version[1] = buffer[1];
ipp->request.any.op_status = (buffer[2] << 8) | buffer[3];
ipp->request.any.request_id = (((((buffer[4] << 8) | buffer[5]) << 8) |
buffer[6]) << 8) | buffer[7];
ipp->request.any.op_status = (buffer[2] << 8) | buffer[3];
ipp->request.any.request_id = (buffer[4] << 24) | (buffer[5] << 16) | (buffer[6] << 8) | buffer[7];

DEBUG_printf(("2ippReadIO: version=%d.%d", buffer[0], buffer[1]));
DEBUG_printf(("2ippReadIO: op_status=%04x",
Expand Down Expand Up @@ -2961,8 +2960,7 @@ ippReadIO(void *src, /* I - Data source */
goto rollback;
}

tag = (ipp_tag_t)((((((buffer[0] << 8) | buffer[1]) << 8) |
buffer[2]) << 8) | buffer[3]);
tag = (ipp_tag_t)((buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3]);

if (tag & IPP_TAG_CUPS_CONST)
{
Expand Down Expand Up @@ -3262,8 +3260,7 @@ ippReadIO(void *src, /* I - Data source */
goto rollback;
}

n = (((((buffer[0] << 8) | buffer[1]) << 8) | buffer[2]) << 8) |
buffer[3];
n = (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];

if (attr->value_tag == IPP_TAG_RANGE)
value->range.lower = value->range.upper = n;
Expand Down Expand Up @@ -3363,14 +3360,9 @@ ippReadIO(void *src, /* I - Data source */
goto rollback;
}

value->resolution.xres =
(((((buffer[0] << 8) | buffer[1]) << 8) | buffer[2]) << 8) |
buffer[3];
value->resolution.yres =
(((((buffer[4] << 8) | buffer[5]) << 8) | buffer[6]) << 8) |
buffer[7];
value->resolution.units =
(ipp_res_t)buffer[8];
value->resolution.xres = (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
value->resolution.yres = (buffer[4] << 24) | (buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
value->resolution.units = (ipp_res_t)buffer[8];
break;

case IPP_TAG_RANGE :
Expand All @@ -3389,12 +3381,8 @@ ippReadIO(void *src, /* I - Data source */
goto rollback;
}

value->range.lower =
(((((buffer[0] << 8) | buffer[1]) << 8) | buffer[2]) << 8) |
buffer[3];
value->range.upper =
(((((buffer[4] << 8) | buffer[5]) << 8) | buffer[6]) << 8) |
buffer[7];
value->range.lower = (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
value->range.upper = (buffer[4] << 24) | (buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
break;

case IPP_TAG_TEXTLANG :
Expand Down
4 changes: 2 additions & 2 deletions cups/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ _cups_md5_process(_cups_md5_state_t *pms, const unsigned char *data /*[64]*/)
int i;

for (i = 0; i < 16; ++i, xp += 4)
X[i] = (unsigned)xp[0] + ((unsigned)xp[1] << 8) +
((unsigned)xp[2] << 16) + ((unsigned)xp[3] << 24);
X[i] = (unsigned)xp[0] | ((unsigned)xp[1] << 8) |
((unsigned)xp[2] << 16) | ((unsigned)xp[3] << 24);

# else /* !ARCH_IS_BIG_ENDIAN */

Expand Down
7 changes: 3 additions & 4 deletions cups/raster-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,12 +685,11 @@ _cupsRasterReadHeader(
r->header.cupsColorSpace = appleheader[1] >= (sizeof(rawcspace) / sizeof(rawcspace[0])) ? CUPS_CSPACE_DEVICE1 : rawcspace[appleheader[1]];
r->header.cupsNumColors = appleheader[1] >= (sizeof(rawnumcolors) / sizeof(rawnumcolors[0])) ? 1 : rawnumcolors[appleheader[1]];
r->header.cupsBitsPerColor = r->header.cupsBitsPerPixel / r->header.cupsNumColors;
r->header.cupsWidth = ((((((unsigned)appleheader[12] << 8) | (unsigned)appleheader[13]) << 8) | (unsigned)appleheader[14]) << 8) | (unsigned)appleheader[15];
r->header.cupsHeight = ((((((unsigned)appleheader[16] << 8) | (unsigned)appleheader[17]) << 8) | (unsigned)appleheader[18]) << 8) | (unsigned)appleheader[19];
r->header.cupsWidth = ((unsigned)appleheader[12] << 24) | ((unsigned)appleheader[13] << 16) | ((unsigned)appleheader[14] << 8) | (unsigned)appleheader[15];
r->header.cupsHeight = ((unsigned)appleheader[16] << 24) | ((unsigned)appleheader[17] << 16) | ((unsigned)appleheader[18] << 8) | (unsigned)appleheader[19];
r->header.cupsBytesPerLine = r->header.cupsWidth * r->header.cupsBitsPerPixel / 8;
r->header.cupsColorOrder = CUPS_ORDER_CHUNKED;
r->header.HWResolution[0] = r->header.HWResolution[1] = ((((((unsigned)appleheader[20] << 8) | (unsigned)appleheader[21]) << 8) | (unsigned)appleheader[22]) << 8) | (unsigned)appleheader[23];

r->header.HWResolution[0] = r->header.HWResolution[1] = ((unsigned)appleheader[20] << 24) | ((unsigned)appleheader[21] << 16) | ((unsigned)appleheader[22] << 8) | (unsigned)appleheader[23];
if (r->header.HWResolution[0] > 0)
{
r->header.PageSize[0] = (r->header.cupsWidth * 72 / r->header.HWResolution[0]);
Expand Down
7 changes: 3 additions & 4 deletions scheduler/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1948,8 +1948,7 @@ get_addr_and_mask(const char *value, /* I - String from config file */
* Merge everything into a 32-bit IPv4 address in ip[3]...
*/

ip[3] = ((((((unsigned)val[0] << 8) | (unsigned)val[1]) << 8) |
(unsigned)val[2]) << 8) | (unsigned)val[3];
ip[3] = (val[0] << 24) | (val[1] << 16) | (val[2] << 8) | val[3];

if (ipcount < 4)
mask[3] = (0xffffffff << (32 - 8 * ipcount)) & 0xffffffff;
Expand All @@ -1976,8 +1975,8 @@ get_addr_and_mask(const char *value, /* I - String from config file */
mask + 3) != 4)
return (0);

mask[3] |= (((((unsigned)mask[0] << 8) | (unsigned)mask[1]) << 8) |
(unsigned)mask[2]) << 8;
mask[3] |= ((unsigned)mask[0] << 24) | ((unsigned)mask[1] << 16) |
((unsigned)mask[2] << 8);
mask[0] = mask[1] = mask[2] = 0;
}
else
Expand Down
2 changes: 1 addition & 1 deletion scheduler/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ mime_check_rules(
else
{
bufptr = fb->buffer + rules->offset - fb->offset;
intv = (unsigned)((((((bufptr[0] << 8) | bufptr[1]) << 8) | bufptr[2]) << 8) | bufptr[3]);
intv = (unsigned)((bufptr[0] << 24) | (bufptr[1] << 16) | (bufptr[2] << 8) | bufptr[3]);
result = (intv == rules->value.intv);
}
break;
Expand Down

0 comments on commit a521b23

Please sign in to comment.