delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/03/25/08:50:13

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:date:message-id:subject:from:to
:content-type; q=dns; s=default; b=vkMqGr/+ojGEy6itDbpPlCulAiCNb
Ft8HJbB5mqlA+oTMUBwogHJE91+SNqY79HzUAoSPrOAhImCFmVraOyUS7/DyQK/4
fQ8q8zzXB/NwZB1oXkZI3EIQ2Nf+fErsfaQWcBd8ayRo7C7sFZ73gQRtMWHcvXNX
L9IAxIfo6qjHVw=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:date:message-id:subject:from:to
:content-type; s=default; bh=JvikVUVHeP/7U6LP/fP6GszvlDM=; b=nKf
ZjEjdOA7TiIH8XbrWVFXEEOpoN0fh6XrrHh1r7MU6PgpdGO3Izx4FV9bNZbTDGPa
K9Xa7sm+vl6qozF3Cv0CODq8kVAXkKy0YU9zrdxBJMRshphJHcrwrOc3YYLCLVsO
IbDZKEybKF+J0Nj/+gc4eKaKDnfB1Z64EOs79/QI=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=2.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2
X-HELO: mail-vc0-f176.google.com
MIME-Version: 1.0
X-Received: by 10.52.242.167 with SMTP id wr7mr796352vdc.32.1395751789767; Tue, 25 Mar 2014 05:49:49 -0700 (PDT)
Date: Tue, 25 Mar 2014 10:19:49 -0230
Message-ID: <CAO+Ld4uHJ6onJifw_TRrmwoFkq+0ZSjgEVEhq61XCDShCPM1Dw@mail.gmail.com>
Subject: Problem with open_memstream
From: Adam Burry <aburry AT ieee DOT org>
To: cygwin AT cygwin DOT com
X-IsSubscribed: yes

I have encountered unexpected behaviour with open_memstream(). Below
is a test case that shows the problem. Shouldn't each invocation of
open_memstream() create a a stream in the same initial state?
Shouldn't 'B' be written to the beginning of the buffer?

I am running Windows 7 Professional Ver 6.1 Build 7601 Service Pack 1
on an 8 processor amd64. My cygwin DLL version is 1.7.28. I am running
the 32-bit install.


Actual output:

test: A
buf: 41 0 0 0 0 0 0 0 0 0
test: B
buf: 0 42 0 0 0 0 0 0 0 0
assertion "0 == strcmp(msg, buf)" failed: file
"test_open_memstream.c", line 33, function: Test
Aborted (core dumped)


Expected output:

test: A
buf: 41 0 0 0 0 0 0 0 0 0
test: B
buf: 42 0 0 0 0 0 0 0 0 0


Test program for GCC 4.8.2 (gcc -Wall -Wextra -pedantic -g
test_open_memstream.c):

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


FILE* RS232_1_tx = 0;


void printbuf(char* buf){
  int i = 0;
  printf("buf: ");
  for (i = 0; i < 10; ++i) {
    printf("%x ", buf[i]); }
  printf("\n"); }


void io_operations(char* msg){
  fprintf(RS232_1_tx, msg); }


void Test(char* msg) {
  char* buf = 0;
  size_t size = 0;
  printf("test: %s\n", msg);
  RS232_1_tx = open_memstream(&buf, &size);
  /* Following fseek required to work around suspected bug in the lib. */
  /* fseek(RS232_1_tx, 0, SEEK_SET); */
  assert(RS232_1_tx);
  io_operations(msg);
  fflush(RS232_1_tx);
  printbuf(buf);
  assert(0 == strcmp(msg, buf));
  fclose(RS232_1_tx);
  RS232_1_tx = 0;
  free(buf); }


int main() {
  Test("A");
  Test("B");
  return 0; }

--
Adam Burry

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019