From derby-dev-return-118900-archive-asf-public=cust-asf.ponee.io@db.apache.org Sat May 5 17:31:04 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id A1E86180671 for ; Sat, 5 May 2018 17:31:03 +0200 (CEST) Received: (qmail 50207 invoked by uid 500); 5 May 2018 15:31:02 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 50195 invoked by uid 99); 5 May 2018 15:31:02 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 05 May 2018 15:31:02 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 2D6911807B2 for ; Sat, 5 May 2018 15:31:02 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -110.311 X-Spam-Level: X-Spam-Status: No, score=-110.311 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id daDECFAXaTH8 for ; Sat, 5 May 2018 15:31:01 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id B9D735F47D for ; Sat, 5 May 2018 15:31:00 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 4BFD2E010F for ; Sat, 5 May 2018 15:31:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 055B821297 for ; Sat, 5 May 2018 15:31:00 +0000 (UTC) Date: Sat, 5 May 2018 15:31:00 +0000 (UTC) From: "Bryan Pendleton (JIRA)" To: derby-dev@db.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (DERBY-6997) Confusing code in NetworkServerControlImpl could be improved MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 Bryan Pendleton created DERBY-6997: -------------------------------------- Summary: Confusing code in NetworkServerControlImpl could be improved Key: DERBY-6997 URL: https://issues.apache.org/jira/browse/DERBY-6997 Project: Derby Issue Type: Improvement Components: Network Server Affects Versions: 10.14.2.0 Reporter: Bryan Pendleton As was discussed on the derby-dev list here: http://mail-archives.apache.org/mod_mbox/db-derby-dev/201802.mbox/%3CCANi-yg8ru8BLNVxW0v6TT_ndPa8Y7_MD6zpgjiyQ6MQoT4Ca9g%40mail.gmail.com%3E it seems like there is some confusing shifting-and-masking code in NetworkServerControlImpl that could be improved: {code:java} private void writeShort(int value) throws Exception { try { commandOs.writeByte((byte)((value & 0xf0) >> 8 )); commandOs.writeByte((byte)(value & 0x0f)); } catch (IOException e) { clientSocketError(e); } } {code} I'm not quite sure what this code is doing. It seems to be mixing some combination of 8-bit shifting and 4-bit value masking. I think it might actually be losing/destroying 4 bits of the 16-bit value (the high 4 bytes in the low byte of the short). For example if you call writeShort(23), it emits 0x00, 0x07, when I think it should emit 0x00,0x17. I suspect the code should read: {code:java} private void writeShort(int value) throws Exception { try { commandOs.writeByte((byte)((value & 0xff00) >> 8 )); commandOs.writeByte((byte)(value & 0x00ff)); } catch (IOException e) { clientSocketError(e); } } {code} or perhaps {code:java} private void writeShort(int value) throws Exception { try { commandOs.writeByte((byte)((value >> 8 )); commandOs.writeByte((byte)value); } catch (IOException e) { clientSocketError(e); } } {code} or some such, but really I don't understand it at all. And, very close to this code is a very similar method: {code:java} private void writeByte(int value) throws Exception { try { commandOs.writeByte((byte)(value & 0x0f)); } catch (IOException e) { clientSocketError(e); } } {code} which I think might be damaged for any value in the range 17-255? It seems like it should probably be: {code:java} private void writeByte(int value) throws Exception { try { commandOs.writeByte((byte)(value & 0xff)); } catch (IOException e) { clientSocketError(e); } } {code} or maybe just: {code:java} private void writeByte(int value) throws Exception { try { commandOs.writeByte((byte)value); } catch (IOException e) { clientSocketError(e); } } {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)