Skip to content

Instantly share code, notes, and snippets.

@pencilcheck
Created March 5, 2012 13:20
Show Gist options
  • Save pencilcheck/1978280 to your computer and use it in GitHub Desktop.
Save pencilcheck/1978280 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <librsync.h>
int
main()
{
FILE *base, *sig;
base = fopen("oldfile", "rb");
sig = fopen("sigfile", "wb");
if (rs_sig_file(base, sig, RS_DEFAULT_BLOCK_LEN, RS_DEFAULT_STRONG_LEN, NULL) == RS_DONE)
return -1;
else
return 0;
}
@skull-squadron
Copy link

~  ᐅ curl -O https://gist.github.com/raw/1978280/c6c7b0189bcf431b01dde6ccf9e4d26a0d569b9a/gistfile1.c
~  ᐅ gcc gistfile1.c -lrsync  -lpthread -ldl -lobjc -I/opt/local/include -L/opt/local/lib
librsynctest.c: In function ‘main’:
librsynctest.c:9: warning: assignment makes pointer from integer without a cast
librsynctest.c:10: warning: assignment makes pointer from integer without a cast
~  ᐅ touch oldfile
~  ᐅ touch sigfile
~  ᐅ ./a.out 
[1]    5185 segmentation fault  ./a.out

@skull-squadron
Copy link

librsync 0.9.7 was installed via port install librsync

@skull-squadron
Copy link

gdb ./a.out 
GNU gdb 6.3.50-20050815 (Apple version gdb-1752) (Sat Jan 28 03:02:46 UTC 2012)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries .... done

(gdb) run
Starting program: /Volumes/Users/barry/a.out 
Already booted .zshenv
Reading symbols for shared libraries +++...warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/blocksort.o" - no debug information available for "blocksort.c".

warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/huffman.o" - no debug information available for "huffman.c".

warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/crctable.o" - no debug information available for "crctable.c".

warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/randtable.o" - no debug information available for "randtable.c".

warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/compress.o" - no debug information available for "compress.c".

warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/decompress.o" - no debug information available for "decompress.c".

warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/bzlib.o" - no debug information available for "bzlib.c".

.................................. done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x000000007b84eef0
0x00007fff9499f398 in feof ()
(gdb) 

@skull-squadron
Copy link

(gdb) start
Breakpoint 1 at 0x100000e6e: file librsynctest.c, line 9.
Starting program: /Volumes/Users/barry/scratch/a.out 
Already booted .zshenv
Reading symbols for shared libraries +++...warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/blocksort.o" - no debug information available for "blocksort.c".

warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/huffman.o" - no debug information available for "huffman.c".

warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/crctable.o" - no debug information available for "crctable.c".

warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/randtable.o" - no debug information available for "randtable.c".

warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/compress.o" - no debug information available for "compress.c".

warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/decompress.o" - no debug information available for "decompress.c".

warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/bzlib.o" - no debug information available for "bzlib.c".

.................................. done

Breakpoint 1, main () at librsynctest.c:9
9       base = rs_file_open("oldfile", "rb");
(gdb) step 
10      sig = rs_file_open("sigfile", "wb");
(gdb) step
11      if (rs_sig_file(base, sig, RS_DEFAULT_BLOCK_LEN, RS_DEFAULT_STRONG_LEN, NULL) == RS_DONE)
(gdb) step

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x000000007b84eef0
0x00007fff9499f398 in feof ()
(gdb)

@skull-squadron
Copy link

Also tried with passing a &stats (of type rs_stats_t) instead of NULL, no workey either. :rage4:

@pencilcheck
Copy link
Author

Try with fopen, it might be it!!

Compiled with
llvm-gcc test.c -lrsync -g3

touch old file
touch sigfile

./a.out

no errors

@skull-squadron
Copy link

Confirmed: rs_sig_file in either arg seg faults. fopen does not. No confidence of actually working (needs more testing). Update: works on both gcc-4.2 and llvm-gcc

@pencilcheck
Copy link
Author

I see no errors and sigfile has something in it, that's my best guess for working state :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment