cleanup

cleanup

--- src/io.h
+++ src/io.h
@@ -17,47 +17,30 @@

   enum Attribute {
     Standout,
-    Red,     BoldRed,
-    Green,   BoldGreen,
-    Yellow,  BoldYellow,
-    Blue,    BoldBlue,
-    Magenta, BoldMagenta,
-    Cyan,    BoldCyan,
-    White,   BoldWhite,
-    Black,   BoldBlack,
+    Red,     BoldRed,     Green,   BoldGreen,
+    Yellow,  BoldYellow,  Blue,    BoldBlue,
+    Magenta, BoldMagenta, Cyan,    BoldCyan,
+    White,   BoldWhite,   Black,   BoldBlack,
     None
   };

   enum Tile {
-    Shadow = ' ',
-    Wall   = '#',
-    Floor  = '.',
-    OpenDoor   = '\'',
-    ClosedDoor   = '+',
-    Trap   = '_',
-    StairsDown = '>',
-    StairsUp = '<',
-    Shop = '~',
+    // Tiles
+    Shadow     = ' ',  Wall       = '#', Floor = '.',
+    OpenDoor   = '\'', ClosedDoor = '+', Trap  = '_',
+    StairsDown = '>',  StairsUp   = '<', Shop  = '~',

-    VerticalBolt = '|',
-    DiagonalUpBolt = '/',
-    HorizontalBolt = '-',
-    DiagonalDownBolt = '\\',
+    // Bolts
+    VerticalBolt   = '|', DiagonalUpBolt   = '/',
+    HorizontalBolt = '-', DiagonalDownBolt = '\\',

-    Gold   = '$',
-    Potion = '!',
-    Scroll = '?',
-    Magic  = '$',
-    Food   = ':',
-    Ammo   = '(',
-    Weapon = ')',
-    Armor  = ']',
-    Amulet = ',',
-    Ring   = '=',
-    Wand   = '/',
+    // Items
+    Gold   = '$', Potion = '!', Scroll = '?', Magic  = '$',
+    Food   = ':', Ammo   = '(', Weapon = ')', Armor  = ']',
+    Amulet = ',', Ring   = '=', Wand   = '/',

+    // Monsters :)
     Player = '@',
-
   };

   char readchar(bool is_question);
@@ -87,20 +70,25 @@
   void print_string(int x, int y, std::string const& str);
   void print_string(std::string const& str);

+  // Start/stop
   void stop_curses();
   void resume_curses();

+  // Map
   static int constexpr map_start_x{20};
   static int constexpr map_start_y{1};
   static int constexpr map_width{80};
   static int constexpr map_height{32};

+  // Screen
   static int constexpr screen_width{100};
   static int constexpr screen_height{35};

+  // Message
   static int constexpr message_x = map_start_x;
   static int constexpr message_y = 0;

+  // Input
   static int constexpr max_input = 50;

 private:


Revert revision 1.3.  This is WARNS=4 clean w/o it and it only increases the diffs to Open/NetBSD.

--- usr.bin/yacc/reader.c
+++ usr.bin/yacc/reader.c
@@ -1884,7 +1884,7 @@
 print_grammar()
 {
     int i, j, k;
-    int spacing = 0;
+    int spacing;
     FILE *f = verbose_file;

     if (!vflag) return;


Header filterData: add default values

Header filterData: add default values

--- libraries/rtprocessing/rtfilter.h
+++ libraries/rtprocessing/rtfilter.h
@@ -116,6 +116,7 @@
     * @param [out] matDataOut - data which is to be filtered
     *
     */
+
     Eigen::MatrixXd filterChannelsConcurrently(const Eigen::MatrixXd& matDataIn,
                                                int iMaxFilterLength,
                                                const QVector<int>& lFilterChannelList,
@@ -141,14 +142,14 @@

     Eigen::MatrixXd filterData(const Eigen::MatrixXd& matDataIn,
                                UTILSLIB::FilterData::FilterType type,
-                               int order,
                                double centerfreq,
                                double bandwidth,
                                double parkswidth,
                                double sFreq,
                                const QVector<int>& lFilterChannelList,
-                               UTILSLIB::FilterData::DesignMethod designMethod = UTILSLIB::FilterData::Cosine,
-                               qint32 fftLength=4096);
+                               int order = 1024,
+                               qint32 fftLength=4096,
+                               UTILSLIB::FilterData::DesignMethod designMethod = UTILSLIB::FilterData::Cosine);

 protected:
     Eigen::MatrixXd                 m_matOverlap;                   /**< Last overlap block */


Free labels when function ends

Free labels when function ends

--- symbol.c
+++ symbol.c
@@ -33,7 +33,7 @@
 	static struct symtab *tbl;
 	register Symbol *sym;

-	tbl = &symtab[ns];
+	tbl = &symtab[(ns >= NR_NAMESPACES) ? NS_IDEN : ns];
 	for (sym = tbl->head; sym; sym = sym->next) {
 		if (sym->ctx <= curctx)
 			break;
@@ -56,6 +56,8 @@

 	freesyms(NS_IDEN);
 	freesyms(NS_TAG);
+	if (curctx == CTX_OUTER)
+		freesyms(NS_LABEL);
 }

 Symbol *


fix #529: Missing error message

fix #529: Missing error message

--- src/kc.c
+++ src/kc.c
@@ -295,7 +295,7 @@
     if(o&&k)O("Elapsed: %.7f\n",d);
   #endif

-  if(o && fam && !strcmp(errmsg,"(nil)"))show(k);
+  if(o && fam && strcmp(errmsg,"type"))show(k);

   cd(k);
  cleanup:


Don't send an authentication failure response if we fail sending a radius accounting packet.

--- usr.sbin/ppp/radius.c
+++ usr.sbin/ppp/radius.c
@@ -96,43 +96,56 @@
   struct in_range dest;
   struct in_addr gw;
   const void *data;
+  const char *stype;

   r->cx.fd = -1;		/* Stop select()ing */
+  stype = r->cx.auth ? "auth" : "acct";

   switch (got) {
     case RAD_ACCESS_ACCEPT:
-      log_Printf(LogPHASE, "Radius: ACCEPT received\n");
+      log_Printf(LogPHASE, "Radius(%s): ACCEPT received\n", stype);
+      if (!r->cx.auth) {
+        rad_close(r->cx.rad);
+        return;
+      }
       break;

     case RAD_ACCESS_REJECT:
-      log_Printf(LogPHASE, "Radius: REJECT received\n");
-      auth_Failure(r->cx.auth);
+      log_Printf(LogPHASE, "Radius(%s): REJECT received\n", stype);
+      if (r->cx.auth)
+        auth_Failure(r->cx.auth);
       rad_close(r->cx.rad);
       return;

     case RAD_ACCESS_CHALLENGE:
       /* we can't deal with this (for now) ! */
       log_Printf(LogPHASE, "Radius: CHALLENGE received (can't handle yet)\n");
-      auth_Failure(r->cx.auth);
+      if (r->cx.auth)
+        auth_Failure(r->cx.auth);
       rad_close(r->cx.rad);
       return;

     case RAD_ACCOUNTING_RESPONSE:
-      log_Printf(LogPHASE, "Radius: Accounting response received\n");
+      log_Printf(LogPHASE, "Radius(%s): Accounting response received\n", stype);
+      if (r->cx.auth)
+        auth_Failure(r->cx.auth);		/* unexpected !!! */
+
       /* No further processing for accounting requests, please */
       rad_close(r->cx.rad);
       return;

     case -1:
-      log_Printf(LogPHASE, "radius: %s\n", rad_strerror(r->cx.rad));
-      auth_Failure(r->cx.auth);
+      log_Printf(LogPHASE, "radius(%s): %s\n", stype, rad_strerror(r->cx.rad));
+      if (r->cx.auth)
+        auth_Failure(r->cx.auth);
       rad_close(r->cx.rad);
       return;

     default:
-      log_Printf(LogERROR, "rad_send_request: Failed %d: %s\n",
+      log_Printf(LogERROR, "rad_send_request(%s): Failed %d: %s\n", stype,
                  got, rad_strerror(r->cx.rad));
-      auth_Failure(r->cx.auth);
+      if (r->cx.auth)
+        auth_Failure(r->cx.auth);
       rad_close(r->cx.rad);
       return;
   }
@@ -455,6 +468,7 @@
   }

+  r->cx.auth = authp;
   if ((got = rad_init_send_request(r->cx.rad, &r->cx.fd, &tv)))
     radius_Process(r, got);
   else {
@@ -462,9 +476,8 @@
     log_Printf(LogDEBUG, "Using radius_Timeout [%p]\n", radius_Timeout);
     r->cx.timer.load = tv.tv_usec / TICKUNIT + tv.tv_sec * SECTICKS;
     r->cx.timer.func = radius_Timeout;
-    r->cx.timer.name = "radius";
+    r->cx.timer.name = "radius auth";
     r->cx.timer.arg = r;
-    r->cx.auth = authp;
     timer_Start(&r->cx.timer);
   }
 }
@@ -609,15 +622,15 @@
       return;
     }

+  r->cx.auth = NULL;			/* Not valid for accounting requests */
   if ((got = rad_init_send_request(r->cx.rad, &r->cx.fd, &tv)))
     radius_Process(r, got);
   else {
     log_Printf(LogDEBUG, "Using radius_Timeout [%p]\n", radius_Timeout);
     r->cx.timer.load = tv.tv_usec / TICKUNIT + tv.tv_sec * SECTICKS;
     r->cx.timer.func = radius_Timeout;
-    r->cx.timer.name = "radius";
+    r->cx.timer.name = "radius acct";
     r->cx.timer.arg = r;
-    r->cx.auth = NULL; /* Not valid for accounting requests */
     timer_Start(&r->cx.timer);
   }
 }


fix #272: MAX_OBJECT_LENGTH

fix #272: MAX_OBJECT_LENGTH

--- src/km.c
+++ src/km.c
@@ -29,7 +29,7 @@
 I PG; //pagesize:  size_t page_size = (size_t) sysconf (_SC_PAGESIZE);

 #if UINTPTR_MAX >= 0xffffffffffffffff //64 bit
-#define MAX_OBJECT_LENGTH (((UI)1) << 45) //for catching obviously incorrect allocations
+#define MAX_OBJECT_LENGTH (((unsigned long long)1) << 45) //for catching obviously incorrect allocations
 #else
 #define MAX_OBJECT_LENGTH (II - 1) //for catching obviously incorrect allocations
 #endif
@@ -115,11 +115,7 @@
 K newK(I t, I n)
 {
   K z;
-#if defined(WIN64)
-  if(n>35e12)R ME;//coarse (ignores bytes per type). but sz can overflow
-#else
-  if(n>MAX_OBJECT_LENGTH)R ME;//coarse (ignores bytes per type). but sz can overflow
-#endif
+  if(n>0 && n>MAX_OBJECT_LENGTH)R ME;//coarse (ignores bytes per type). but sz can overflow
   I k=sz(t,n);
   U(z=kalloc(k))
   //^^ relies on MAP_ANON being zero-filled for 0==t || 5==t (cd() the half-complete), 3==ABS(t) kC(z)[n]=0 (+-3 types emulate c-string)


Cosmetic change

Cosmetic change

--- src/nb.c
+++ src/nb.c
@@ -256,9 +256,7 @@
   {
     die("repository doesn't exist: \"%s\"", arg_list[1]);
   }
-
-  struct stat repo_stats = sStat(arg_list[1]);
-  if(!S_ISDIR(repo_stats.st_mode))
+  else if(!S_ISDIR(sStat(arg_list[1]).st_mode))
   {
     die("not a directory: \"%s\"", arg_list[1]);
   }


[Core] Ui: It's more legible with color.

--- src/ui.c
+++ src/ui.c
@@ -29,6 +29,7 @@
 #define COLOR_ROSTER (ui_color(COLOR_THEME, hftirc->ui->bg))
 #define COLOR_ACT    (ui_color(COLOR_WHITE,  COLOR_THEME) | A_UNDERLINE)
 #define COLOR_HLACT  (ui_color(COLOR_RED, COLOR_THEME) | A_BOLD | A_UNDERLINE)
+#define COLOR_LASTPOS (ui_color(COLOR_BLUE, hftirc->ui->bg | A_BOLD ))

 void
 ui_init(void)
@@ -308,7 +309,7 @@

      /* Last position tracker with bold line */
      if(hftirc->cb[hftirc->selbuf].lastposbold == n)
-          lastposmask |= A_BOLD;
+          lastposmask |= COLOR_LASTPOS;

      for(i = 0; i < strlen(str); ++i)
      {


- possibly fall back to user-to-user verification if we get KRB5_KT_NOTFOUND

--- src/v5.c
+++ src/v5.c
@@ -1288,6 +1288,7 @@
 		switch (krberr) {
 		case EACCES:
 		case ENOENT:
+		case KRB5_KT_NOTFOUND:
 			/* We weren't able to read the keytab. */
 			if (options->validate_user_user &&
 			    (_pam_krb5_sly_looks_unsafe() == 0)) {


bugfix for top level return.

bugfix for top level return.

--- src/vm.c
+++ src/vm.c
@@ -33,20 +33,6 @@
 #include "c_hash.h"

-/***** Macros ***************************************************************/
-/*
-   Top-level return immediately stops the program (task) and
-   doesn't handle its arguments
- */
-#define STOP_IF_TOPLEVEL()            \
-  do {                                \
-    if( vm->callinfo_tail == NULL ) { \
-      vm->flag_preemption = 1;        \
-      return -1;                      \
-    }                                 \
-  } while (0)
-
-
 static uint16_t free_vm_bitmap[MAX_VM_COUNT / 16 + 1];

 #define CALL_MAXARGS 255
@@ -176,8 +162,8 @@
 */
 void mrbc_pop_callinfo( struct VM *vm )
 {
+  assert( vm->callinfo_tail );
   mrbc_callinfo *callinfo = vm->callinfo_tail;
-  if( !callinfo ) return;

   vm->callinfo_tail = callinfo->prev;
   vm->cur_regs = callinfo->cur_regs;
@@ -1386,18 +1372,21 @@
 {
   FETCH_B();

+  // return without anything if top level.
+  if( vm->callinfo_tail == NULL ) {
+    vm->flag_preemption = 1;
+    return -1;
+  }
+
+  // set return value
   mrbc_decref(&regs[0]);
   regs[0] = regs[a];
   regs[a].tt = MRBC_TT_EMPTY;

-  assert( vm->exc.tt == MRBC_TT_NIL );
-
-  STOP_IF_TOPLEVEL();
-
-  mrbc_pop_callinfo(vm);
-
   // nregs to release
   int nregs = vm->cur_irep->nregs;
+
+  mrbc_pop_callinfo(vm);

   // clear stacked arguments
   int i;
@@ -1453,18 +1442,28 @@
       callinfo = vm->callinfo_tail;
     } while( callinfo != caller_callinfo );

+    // return without anything if top level.
+    if( callinfo == NULL ) {
+      vm->flag_preemption = 1;
+      return -1;
+    }
+
     p_reg = callinfo->cur_regs + callinfo->reg_offset;

   } else {
     p_reg = &regs[0];
+  }
+
+  // return without anything if top level.
+  if( vm->callinfo_tail == NULL ) {
+    vm->flag_preemption = 1;
+    return -1;
   }

   // set return value
   mrbc_decref( p_reg );
   *p_reg = regs[a];
   regs[a].tt = MRBC_TT_EMPTY;
-
-  STOP_IF_TOPLEVEL();

   mrbc_pop_callinfo(vm);


bugfix. op_raiseif, op_return_blk and op_break.

--- src/vm.c
+++ src/vm.c
@@ -1007,28 +1007,39 @@
 {
   FETCH_B();

-  if( regs[a].tt != MRBC_TT_JMPUW ) {
-    assert( mrbc_type(regs[a]) == MRBC_TT_EXCEPTION ||
-	    mrbc_type(regs[a]) == MRBC_TT_NIL );
+  if( regs[a].tt == MRBC_TT_BREAK ) {
     vm->exc = regs[a];
+    const mrbc_irep_catch_handler *handler = catch_handler_find(vm, 0, MRBC_CATCH_FILTER_ENSURE);
+    if( handler ) {
+      vm->inst = vm->cur_irep->inst + bin_to_uint32(handler->target);
+    } else {
+      vm->inst = regs[a].jmpuw;
+    }
     return 0;
   }

-  const mrbc_irep_catch_handler *handler = catch_handler_find(vm, 0, MRBC_CATCH_FILTER_ENSURE);
-  if( !handler ) {
-    vm->inst = regs[a].jmpuw;
+  if( regs[a].tt == MRBC_TT_JMPUW ) {
+    const mrbc_irep_catch_handler *handler = catch_handler_find(vm, 0, MRBC_CATCH_FILTER_ENSURE);
+    if( !handler ) {
+      vm->inst = regs[a].jmpuw;
+      return 0;
+    }
+
+    uint32_t jump_point = regs[a].jmpuw - vm->cur_irep->inst;
+    if( (bin_to_uint32(handler->begin) < jump_point) &&
+	(jump_point <= bin_to_uint32(handler->end)) ) {
+      vm->inst = regs[a].jmpuw;
+      return 0;
+    }
+
+    vm->exc = regs[a];
+    vm->inst = vm->cur_irep->inst + bin_to_uint32(handler->target);
     return 0;
   }

-  uint32_t jump_point = regs[a].jmpuw - vm->cur_irep->inst;
-  if( (bin_to_uint32(handler->begin) < jump_point) &&
-      (jump_point <= bin_to_uint32(handler->end)) ) {
-    vm->inst = regs[a].jmpuw;
-    return 0;
-  }
-
+  assert( mrbc_type(regs[a]) == MRBC_TT_EXCEPTION ||
+	  mrbc_type(regs[a]) == MRBC_TT_NIL );
   vm->exc = regs[a];
-  vm->inst = vm->cur_irep->inst + bin_to_uint32(handler->target);
   return 0;
 }

@@ -1379,7 +1390,6 @@
   regs[0] = regs[a];
   regs[a].tt = MRBC_TT_EMPTY;

-  //vm->exc = mrbc_nil_value();		// TODO
   assert( vm->exc.tt == MRBC_TT_NIL );

   STOP_IF_TOPLEVEL();
@@ -1412,13 +1422,24 @@
 {
   FETCH_B();

-  // check if in an ensure block.
-  const mrbc_irep_catch_handler *catch_handler = catch_handler_find(vm, 0, MRBC_CATCH_FILTER_ENSURE);
-  if( catch_handler ) {
-    vm->inst = vm->cur_irep->inst + bin_to_uint32(catch_handler->target);
+  // check return from ensure.
+  if( vm->exc.tt == MRBC_TT_BREAK ) {
+    vm->exc.tt = MRBC_TT_NIL;
+    goto RETURN_TO_OUT_OF_BLOCK;
+  }
+
+  // if in catch handler, jump to ensure.
+  // and then return back via OP_RAISEIF.
+  const mrbc_irep_catch_handler *handler = catch_handler_find(vm, 0, MRBC_CATCH_FILTER_ENSURE);
+  if( handler ) {
+    vm->exc.tt = MRBC_TT_BREAK;
+    vm->exc.jmpuw = vm->inst - 2;	// 2 is size of OP_RETURN_BRK
+    vm->inst = vm->cur_irep->inst + bin_to_uint32(handler->target);
     return 0;
   }

+
+ RETURN_TO_OUT_OF_BLOCK:;
   int nregs = vm->cur_irep->nregs;
   mrbc_value *p_reg;

@@ -1471,6 +1492,24 @@

   assert( regs[0].tt == MRBC_TT_PROC );

+  // check return from ensure.
+  if( vm->exc.tt == MRBC_TT_BREAK ) {
+    vm->exc.tt = MRBC_TT_NIL;
+    goto RETURN_TO_OUT_OF_BLOCK;
+  }
+
+  // if in catch handler, jump to ensure.
+  // and then return back via OP_RAISEIF.
+  const mrbc_irep_catch_handler *handler = catch_handler_find(vm, 0, MRBC_CATCH_FILTER_ENSURE);
+  if( handler ) {
+    vm->exc.tt = MRBC_TT_BREAK;
+    vm->exc.jmpuw = vm->inst - 2;	// 2 is size of OP_BREAK
+    vm->inst = vm->cur_irep->inst + bin_to_uint32(handler->target);
+    return 0;
+  }
+
+
+ RETURN_TO_OUT_OF_BLOCK:;
   int nregs = vm->cur_irep->nregs;
   mrbc_callinfo *callinfo = vm->callinfo_tail;
   mrbc_callinfo *caller_callinfo = regs[0].proc->callinfo;


modules: add system.exit(code)

modules: add system.exit(code)

--- src/vm.c
+++ src/vm.c
@@ -46,6 +46,14 @@
     fprintf(stderr, "FATAL %ld: %s\n", (long) code, (const char *) (msg ? msg : "null"));
     fflush(stderr);
     abort();
+}
+
+
+static duk_ret_t sjs__exit(duk_context* ctx) {
+    int code = duk_require_int(ctx, 0);
+    /* TODO: properly tear down the vm */
+    exit(code);
+    return -42;    /* control never returns here */
 }

@@ -150,6 +158,12 @@
         duk_put_prop_string(ctx, -2, "platform");
     }

+    /* system.exit(x) */
+    {
+	duk_push_c_function(ctx, sjs__exit, 1 /* nargs */);
+	duk_put_prop_string(ctx, -2, "exit");
+    }
+
     duk_pop(ctx);
 }


Rename structs

Rename structs

--- src/vm.h
+++ src/vm.h
@@ -17,7 +17,7 @@
 */
 typedef struct hvm_chunk {

-} hvm_chunk_t;
+} hvm_chunk;

 /**
 @brief Stores instructions, constants, etc. for a chunk. Can then generate the
@@ -25,13 +25,13 @@
 */
 typedef struct hvm_generator {
   // nothing
-} hvm_generator_t;
+} hvm_generator;

 /**
 Generates bytecode.
 @memberof hvm_generator
 */
-void hvm_generator_bytecode(hvm_generator_t*);
+void hvm_generator_bytecode(hvm_generator*);

 /// Instance of the VM.
 typedef struct hvm_vm {
@@ -40,12 +40,12 @@
   // instruction pointer
   // heap
   // object space
-} hvm_vm_t;
+} hvm_vm;

 /// Opcodes
-typedef enum hvm_opcode {
+typedef enum {
   HVM_OP_NOOP = 0,
   HVM_OP_GOTO = 1
-} hvm_opcode_t;
+} hvm_opcodes;

 #endif


wc should only check stdin once

wc should only check stdin once

--- src/wc.c
+++ src/wc.c
@@ -12,7 +12,7 @@
   putchar('\n');
 }

-struct Wc wc(int fd) { /* counts both utf8 chars and bytes, assuming valid utf8 */
+static struct Wc wc(int fd) { /* counts both utf8 chars and bytes, assuming valid utf8 */
   size_t words = 0, chars = 0, bytes = 0, lines = 0;
   int inword = 0;
   unsigned char buffer[bufsize];
@@ -39,7 +39,7 @@
 int main(int argc, char *argv[]) {
   options("wclm");
   int fl = (!!flag('w')) | (!!flag('c'))<<1 | flag('l')<<2 | (!!flag('m'))<<3;
-  int saverrno, file = 0;
+  int saverrno, file = 0, stdinonce = 0;
   FILE *fileptr = stdin;
   if (!fl) {
     fl = 1|2|4;
@@ -57,6 +57,10 @@
     else fileptr = fdopen(file, "r");
 inner:
     saverrno = errno;
+    if (fileptr == stdin && stdinonce) {
+      count = (struct Wc) { 0 };
+      goto readdone;
+    }
     if (fl == 2) {
       struct stat st;
       if (fstat(file, &st) == -1) goto readit;
@@ -75,7 +79,7 @@
       tot.w += count.w;
       printwc(count, argc == 1 ? NULL : *argv);
     }
-    if (fileptr != stdin) close(file);
+    if (fileptr != stdin || !stdinonce++) close(file);
   }
   if (argc > 2) printwc(tot, "total");
   return errno;


Handle absolute pathnames correctly in dtc_open_file.

Also, free file->dir when freeing file.

Signed-off-by: Scott Wood <b77916c2feab81a70245e7b5671f4f02730ebf64@freescale.com>

--- srcpos.c
+++ srcpos.c
@@ -86,6 +86,16 @@
 		return file;
 	}

+	if (fname[0] == '/') {
+		file->file = fopen(fname, "r");
+
+		if (!file->file)
+			goto out;
+
+		file->name = strdup(fname);
+		return file;
+	}
+
 	if (!search)
 		search = &default_search;

@@ -100,6 +110,7 @@
 	}

 out:
+	free((void *)file->dir);
 	free(file);
 	return NULL;
 }
@@ -109,5 +120,6 @@
 	if (fclose(file->file))
 		die("Error closing \"%s\": %s\n", file->name, strerror(errno));

+	free((void *)file->dir);
 	free(file);
 }


sscall: Update comments

sscall: Update comments

Signed-off-by: Dimitris Papastamos <a91262282f71bb8488398dcc9202f777d0206664@opensource.wolfsonmicro.com>

--- sscall.c
+++ sscall.c
@@ -152,10 +152,12 @@
 			cbuf = list_entry(iter, struct compressed_buf,
 					  list);

+			/* Decode compressed buffer */
 			pthread_mutex_lock(&speex_jitter_lock);
 			speex_jitter_get(&speex_jitter, pcm, 0);
 			pthread_mutex_unlock(&speex_jitter_lock);

+			/* Play via libao */
 			ao_play(device, (void *)pcm, sizeof(pcm));

 			free(cbuf->buf);
@@ -344,10 +346,13 @@
 	/* Create a new encoder/decoder state in wideband mode */
 	speex_enc_state = speex_encoder_init(&speex_wb_mode);
 	speex_dec_state = speex_decoder_init(&speex_wb_mode);
+	/* Set the encoder's quality */
 	tmp = 8;
 	speex_encoder_ctl(speex_enc_state, SPEEX_SET_QUALITY, &tmp);
 	tmp = 2;
+	/* Set the encoder's complexity */
 	speex_encoder_ctl(speex_enc_state, SPEEX_SET_COMPLEXITY, &tmp);
+	/* Init the Speex Jitter Buffer */
 	speex_jitter_init(&speex_jitter, speex_dec_state);
 }

@@ -534,8 +539,8 @@
 	if (signal(SIGUSR1, sig_handler) == SIG_ERR)
 		err(1, "signal");

-	/* Receive audio data from other end and prepare
-	 * for playback */
+	/* Main processing loop, receive compressed data,
+	 * parse and prepare for playback */
 	do {
 		/* Handle SIGINT gracefully */
 		if (handle_sigint) {


Attempt to preverify with a progressively truncated peer-supplied certificate chain if preverification fails

--- packages/ssl/ssllib.c
+++ packages/ssl/ssllib.c
@@ -517,6 +517,68 @@
         int   err;
         const char *error;

+        /* At this point, we have a slight divergence from what happens in web
+         * browsers. Verisign (at least) has cross-signed certificates, which
+         * apparently means that we can have more than one certification path.
+         * For example, the server may supply:
+         * peer -> intermediate CA 1 -> intermediate CA 2 -> Root CA
+         * OpenSSL will respect this supplied chain.
+         * Firefox and IE (at least) have a different version of
+         * intermediate CA 2, which is self-signed and trusted, but has the same
+         * public key as the intermediate CA 2 which is issued by the Root CA.
+         * The result is that if you supply the intermediate CA 2 as known to
+         * the web broswer via cacert_file in ssl_init, OpenSSL will fail to
+         * authenticate.
+         *
+         * There are two solutions. Obviously, we can supply the Root CA as the
+         * server is clearly expecting. Another is to progressively truncate the
+         * certificate chain if we encounter an error. After one step, in this
+         * case, OpenSSL will inject the trusted CA in at the top of the chain
+         * and approve the chain.
+         *
+         * Some people might argue this constitutes a security hole, since if
+         * the Intermediate CA 2 which is signed by the Root CA is revoked or
+         * expires, we will still authenticate the chain if we trust the self-
+         * signed intermediate 2 CA. I contend that if we really do trust the
+         * self-signed CA, then intermediate CA 1, which is signed by the same
+         * public key as our self-signed CA should also be trusted, regardless
+         * of what has happened to its brother who was signed by the Root CA.
+         *
+         * Because this change is localised, it could ultimately be controlled
+         * by a flag?
+         */
+
+        X509 *top_server_supplied, *top_untrusted, *next_certificate;
+
+        /* Remove the top certificates from each chain and keep them for later
+         * Note that we aren't supposed to access ctx->chain and ctx->untrusted
+         * directly, but there appears to be no other way to access them?
+         */
+        top_server_supplied = sk_X509_pop(ctx->chain);
+        top_untrusted = sk_X509_pop(ctx->untrusted);
+
+        /* Next examine to see if we're at the bottom of the chain */
+        if ((next_certificate = sk_X509_pop(ctx->chain)) != NULL)
+        {
+           /* We're not, so put the certificate back on (this could be avoided if
+              there were an sk_X509_peek, obviously
+           */
+           sk_X509_push(ctx->chain, next_certificate);
+
+           /* Set the top certificate to be the next certificate down */
+           X509_STORE_CTX_set_cert(ctx, next_certificate);
+
+           /* And try validating the resulting chain */
+           if (X509_verify_cert(ctx) == 1)
+           {
+              return 1;
+           }
+        }
+
+        /* We failed to pre-verify, so put the certs we removed back and continue */
+        sk_X509_push(ctx->chain, top_server_supplied);
+        sk_X509_push(ctx->untrusted, top_untrusted);
+
         /*
          * Get certificate
          */


config: remove execute permission on C source file

Was originally created like that in git in 2003.

Acked-by: Yaakov Selkowitz <39f9896da8aeb99e60369082c8cb330d7a467d84@users.sourceforge.net>
Signed-off-by: Gaetan Nadon <8a8cc541338200f67d4d0bcb65c78b6166649462@videotron.ca>


keypair, box, box_open, randombytes working

--- sodium.c
+++ sodium.c
@@ -26,6 +26,7 @@
 #include "php.h"
 #include "php_sodium.h"
 #include "sodium.h"
+#include "Zend/zend_exceptions.h"

 static int le_crypto;

@@ -34,61 +35,192 @@

 zend_class_entry *php_sodium_nonce_entry;
 static zend_object_handlers php_sodium_nonce_object_handlers;
+
+zend_class_entry *php_sodium_public_key_entry;
+static zend_object_handlers php_sodium_public_key_object_handlers;
+
+zend_class_entry *php_sodium_secret_key_entry;
+static zend_object_handlers php_sodium_secret_key_object_handlers;
+
+zend_class_entry *php_sodium_crypto_exception_entry;
+
+typedef struct _php_sodium_nonce_data {
+	struct timeval	ts;
+	unsigned char rand[8];
+	unsigned long long counter;
+} php_sodium_nonce_data;

 typedef struct _php_sodium_nonce {
 	zend_object std;
 	unsigned char *last;
 	unsigned char *current;
+	php_sodium_nonce_data *data;
 } php_sodium_nonce;

-typedef struct _php_sodium_nonce_data {
-	struct timeval	ts;
-	unsigned char rand[8];
-	long long counter;
-} php_sodium_nonce_data;
-
-/* {{{ php_bin2hex */
-static char hexconvtab[] = "0123456789abcdef";
-
-static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t *newlen)
-{
+typedef struct _php_sodium_key {
+	zend_object std;
+	unsigned char *public;
+	unsigned char *secret;
+} php_sodium_key;
+
+static int php_sodium_little_endian;
+
+/* {{{ void lltos(long long v, sizeof(v), s, direction)
+	Converts a long long to string s lltos is a ptr set to lltos_big or llto_little for corrent endian behavior
+*/
+static void (*lltos)(void *v, size_t vsize, unsigned char *s, int direction);
+/* }}} */
+
+/* {{{ lltos_big */
+static void lltos_big(void *v, size_t vsize, unsigned char *s, int direction) {
+
+	unsigned char *p = (unsigned char *) v;
+	int i = 0;
+	int max = vsize - 1;
+
+	for (; i <= max ; i++) {
+
+		if (direction) {
+			s[i] = p[i];
+		}
+		else {
+			p[i] = s[i];
+		}
+	}
+}
+/* }}} */
+
+/* {{{ lltos_little */
+static void lltos_little(void *v, size_t vsize, unsigned char *s, int direction) {
+
+	unsigned char *p = (unsigned char *) v;
+	int i = 0;
+	int max = vsize - 1;
+
+	for (; i <= max ; i++) {
+
+		if (direction) {
+			s[max - i] = p[i];
+		}
+		else {
+			p[i] = s[max - i];
+		}
+	}
+}
+/* }}} */
+
+/* {{{ php_sodium_hex */
+static char *php_sodium_hex(const unsigned char *old, const size_t oldlen) {
+
+	static char hexconvtab[] = "0123456789abcdef";
 	register unsigned char *result = NULL;
 	size_t i, j;
-
-	result = (unsigned char *) safe_emalloc(oldlen, 2 * sizeof(char), 1);
+	int result_len = (oldlen * 2);
+	result = (unsigned char *) safe_emalloc(result_len + 1, sizeof(unsigned char), 1);
+	*(result + result_len) = 0;

 	for (i = j = 0; i < oldlen; i++) {
 		result[j++] = hexconvtab[old[i] >> 4];
 		result[j++] = hexconvtab[old[i] & 15];
 	}
-	result[j] = '\0';
-
-	if (newlen)
-		*newlen = oldlen * 2 * sizeof(char);

 	return (char *)result;
 }
 /* }}} */

+/* {{{ php_hex2bin(const unsignec char *old, const size_t oldlen, size_t *newlen)
+	(from php 5.4 string.c)
+*/
+static char *php_hex2bin(const unsigned char *old, const size_t oldlen, size_t *newlen) {
+
+    size_t target_length = oldlen >> 1;
+    register unsigned char *str = (unsigned char *)safe_emalloc(target_length, sizeof(char), 1);
+    size_t i, j;
+    for (i = j = 0; i < target_length; i++) {
+        char c = old[j++];
+        if (c >= '0' && c <= '9') {
+            str[i] = (c - '0') << 4;
+        } else if (c >= 'a' && c <= 'f') {
+            str[i] = (c - 'a' + 10) << 4;
+        } else if (c >= 'A' && c <= 'F') {
+            str[i] = (c - 'A' + 10) << 4;
+        } else {
+            efree(str);
+            return NULL;
+        }
+        c = old[j++];
+        if (c >= '0' && c <= '9') {
+            str[i] |= c - '0';
+        } else if (c >= 'a' && c <= 'f') {
+            str[i] |= c - 'a' + 10;
+        } else if (c >= 'A' && c <= 'F') {
+            str[i] |= c - 'A' + 10;
+        } else {
+            efree(str);
+            return NULL;
+        }
+    }
+    str[target_length] = '\0';
+
+    if (newlen)
+        *newlen = target_length;
+
+    return (char *)str;
+}
+/* }}} */
+
+/* {{{
+	Used for testing endian
+	reverse_num((unsigned char *) &a, (unsigned char *) &t, sizeof(a));
+void reverse_num(unsigned char *in, unsigned char *out, size_t size) {
+
+	int i;
+
+	for(i = 0; i < size; i++) {
+
+		out[i] = in[size - i - 1];
+	}
+}
+ }}} */
+
 #define PHP_SODIUM_NONCE (php_sodium_nonce *) zend_object_store_get_object(getThis() TSRMLS_CC);

-/* {{{ static void php_sodium_nonce_free_object_storage(void *object TSRMLS_DC) { */
+#define PHP_SODIUM_KEY (php_sodium_key *) zend_object_store_get_object(getThis() TSRMLS_CC);
+
+#define PHP_SODIUM_E_BAD_NONCE (1<<0L)
+#define PHP_SODIUM_E_LOAD_PUBLICKEY (1<<1L)
+#define PHP_SODIUM_E_LOAD_SECRETKEY (1<<2L)
+#define PHP_SODIUM_E_BAD_PUBLICKEY (1<<3L)
+#define PHP_SODIUM_E_BAD_SECRETKEY (1<<4L)
+#define PHP_SODIUM_E_KEYPAIR_FAILED (1<<5L)
+#define PHP_SODIUM_E_BOX_FAILED (1<<6L)
+#define PHP_SODIUM_E_BOX_OPEN_FAILED (1<<7L)
+
+#define PHP_SODIUM_ERROR_HANDLING_INIT() zend_error_handling error_handling;
+
+#define PHP_SODIUM_ERROR_HANDLING_THROW() zend_replace_error_handling(EH_THROW, php_sodium_crypto_exception_entry, &error_handling TSRMLS_CC);
+
+#define PHP_SODIUM_ERROR_HANDLING_RESTORE() zend_restore_error_handling(&error_handling TSRMLS_CC);
+
+/* {{{ static void php_sodium_nonce_free_object_storage(void *object TSRMLS_DC) */
 static void php_sodium_nonce_free_object_storage(void *object TSRMLS_DC) {

 	php_sodium_nonce *intern = (php_sodium_nonce *) object;

-	if(! intern) {
-		return;
-	}
-
-	if(intern->last) {
+	if (! intern) {
+		return;
+	}
+
+	if (intern->last) {
 		efree(intern->last);
-		intern->last = NULL;
-	}
-
-	if(intern->current) {
+	}
+
+	if (intern->current) {
 		efree(intern->current);
-		intern->current = NULL;
+	}
+
+	if (intern->data) {
+		efree(intern->data);
 	}

 	zend_object_std_dtor(&intern->std TSRMLS_CC);
@@ -108,6 +240,7 @@
 	object_properties_init(&intern->std, class_type);
 	intern->last = NULL;
 	intern->current = NULL;
+	intern->data = NULL;

 	zov.handle = zend_objects_store_put(
 		  intern
@@ -120,12 +253,51 @@
 }
 /* }}} */

-/* {{{ php_sodium_nonce_destroy(php_sodium_nonce *intern */
-static void php_sodium_nonce_destroy(php_sodium_nonce *internal) {
-
-}
-/* }}} */
-
+/* {{{ static void php_sodium_key_free_object_storage(void *object TSRMLS_DC) */
+static void php_sodium_key_free_object_storage(void *object TSRMLS_DC) {
+
+	php_sodium_key *intern = (php_sodium_key *) object;
+
+	if (! intern) {
+		return;
+	}
+
+	if (intern->public) {
+		efree(intern->public);
+	}
+
+	if (intern->secret) {
+		efree(intern->secret);
+	}
+
+	zend_object_std_dtor(&intern->std TSRMLS_CC);
+	efree(intern);
+}
+/* }}} */
+
+/* {{{ zend_object_value php_sodium_key_ctor(zend_class_entry *class_type TSRMLS_DC) */
+static zend_object_value php_sodium_key_ctor(zend_class_entry *class_type TSRMLS_DC) {
+
+	zend_object_value zov;
+	php_sodium_key *intern;
+
+	intern = (php_sodium_key *) emalloc(sizeof(*intern));
+	memset(&intern->std, 0, sizeof(zend_object));
+	zend_object_std_init(&intern->std, class_type TSRMLS_CC);
+	object_properties_init(&intern->std, class_type);
+	intern->public = NULL;
+	intern->secret = NULL;
+
+	zov.handle = zend_objects_store_put(
+		  intern
+		, NULL
+		, (zend_objects_free_object_storage_t) php_sodium_key_free_object_storage
+		, NULL TSRMLS_CC
+	);
+	zov.handlers = (zend_object_handlers *) &php_sodium_public_key_object_handlers;
+	return zov;
+}
+/* }}} */

 /* {{{ proto crypto crypto::__construct()
 	ctor */
@@ -140,135 +312,173 @@
 PHP_METHOD(crypto, __destruct) { }
 /* }}} */

-/* {{{ proto void crypto::keypair(string &$public_key, string &$secret_key)
-	Generates a new $public_key and $secret_key
+/* {{{ proto mixed crypto::keypair()
+	Generates a new secret_key
 */
 PHP_METHOD(crypto, keypair)
 {
-	zval *pk;
-	zval *sk;
-
-	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &pk, &sk) == FAILURE) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed parsing parms");
-		RETURN_FALSE;
-	}
-
-	zval_dtor(pk);
-	zval_dtor(sk);
-	unsigned char *pkout = safe_emalloc(crypto_box_PUBLICKEYBYTES + 1, sizeof(unsigned char), 1);
-	unsigned char *skout = safe_emalloc(crypto_box_SECRETKEYBYTES + 1, sizeof(unsigned char), 1);
-	int rc = crypto_box_keypair(pkout, skout);
+	object_init_ex(return_value, php_sodium_secret_key_entry);
+	php_sodium_key *key = (php_sodium_key *) zend_object_store_get_object(return_value TSRMLS_CC);
+	key->public = safe_emalloc(crypto_box_PUBLICKEYBYTES, sizeof(unsigned char), 1);
+	key->secret = safe_emalloc(crypto_box_SECRETKEYBYTES, sizeof(unsigned char), 1);
+
+	int rc = crypto_box_keypair(key->public, key->secret);

-	if(rc != 0) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "crypto_box_keypair failed: %d", rc);
-		RETURN_FALSE;
-	}
-
-	*(pkout + crypto_box_PUBLICKEYBYTES) = 0x0;
-	*(skout + crypto_box_SECRETKEYBYTES) = 0x0;
-
-	ZVAL_STRINGL(pk, pkout, crypto_box_PUBLICKEYBYTES, 0);
-	ZVAL_STRINGL(sk, skout, crypto_box_SECRETKEYBYTES, 0);
-}
-/* }}} */
-
-/* {{{ proto string crytpo::box(string $plain_text, string $nonce, string $receiver_public_key, string $sender_secret_key)
+	if (rc != 0) {
+
+		zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_KEYPAIR_FAILED TSRMLS_CC, "crypto_box_keypair failed: %d", rc);
+		return;
+	}
+
+	zend_update_property_stringl(php_sodium_secret_key_entry, return_value, "pbin", strlen("pbin"), key->public, crypto_box_PUBLICKEYBYTES TSRMLS_CC);
+	zend_update_property_stringl(php_sodium_secret_key_entry, return_value, "sbin", strlen("sbin"), key->secret, crypto_box_SECRETKEYBYTES TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ proto string crytpo::box(string $plain_text, nonce $nonce, public_key $receiver, secret_key $sender)
 	Encrypts $plain_text with $nonce and keys
 */
 PHP_METHOD(crypto, box)
 {
-	unsigned char *c, *m, *plain_text, *n, *pk, *sk;
-	int plain_text_len, n_len, pk_len, sk_len;
-
-	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssss", &plain_text, &plain_text_len, &n, &n_len, &pk, &pk_len, &sk, &sk_len) == FAILURE) {
-		RETURN_FALSE;
-	}
-
-	if(n_len != crypto_box_NONCEBYTES) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Nonce length must be %d bytes. Actual length is %d bytes", crypto_box_NONCEBYTES, n_len);
-		RETURN_FALSE;
-	}
-
-	if(pk_len != crypto_box_PUBLICKEYBYTES) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "$receiver_public_key length must be %d bytes. Actual length is %d bytes", crypto_box_PUBLICKEYBYTES, pk_len);
-		RETURN_FALSE;
-	}
-
-	if(sk_len != crypto_box_SECRETKEYBYTES) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "$send_secret_key length must be %d bytes. Actual length is %d bytes", crypto_box_SECRETKEYBYTES, sk_len);
-		RETURN_FALSE;
+	unsigned char *c, *m, *plain_text;
+	zval *zn, *zpk, *zsk;
+	int plain_text_len;
+	php_sodium_nonce *nonce;
+	php_sodium_key *public_key;
+	php_sodium_key *secret_key;
+
+	PHP_SODIUM_ERROR_HANDLING_INIT()
+	PHP_SODIUM_ERROR_HANDLING_THROW()
+
+	int rc = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sOOO", &plain_text, &plain_text_len, &zn, php_sodium_nonce_entry, &zpk, php_sodium_public_key_entry, &zsk, php_sodium_secret_key_entry);
+
+	PHP_SODIUM_ERROR_HANDLING_RESTORE()
+
+	if (rc == FAILURE) {
+
+		return;
+	}
+
+	nonce = (php_sodium_nonce *) zend_object_store_get_object(zn TSRMLS_CC);
+
+	if (! nonce->current) {
+
+		zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_BAD_NONCE TSRMLS_CC, "nonce is missing a current value. Call nonce::next() or nonce::set_nonce()");
+		return;
+	}
+
+	public_key = (php_sodium_key *) zend_object_store_get_object(zpk TSRMLS_CC);
+
+	if (! public_key->public) {
+
+		zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_LOAD_PUBLICKEY TSRMLS_CC, "public_key is missing a key. Call public_key::load()");
+		return;
+	}
+
+	secret_key = (php_sodium_key *) zend_object_store_get_object(zsk TSRMLS_CC);
+
+	if (! secret_key->secret) {
+
+		zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_LOAD_SECRETKEY TSRMLS_CC, "secret_key is missing a key. Call secret_key::load()");
+		return;
 	}

 	int m_len = crypto_box_ZEROBYTES + plain_text_len;
 	m = safe_emalloc(m_len, sizeof(unsigned char), 1);
-	memset(m, 0x0, crypto_box_ZEROBYTES);
+	memset(m, 0, crypto_box_ZEROBYTES);
 	memcpy(m + crypto_box_ZEROBYTES, plain_text, plain_text_len);

 	c = safe_emalloc(m_len + 1, sizeof(unsigned char), 1);
-	int rc = crypto_box(c, m, m_len, n, pk, sk);
+	rc = crypto_box(c, m, m_len, nonce->current, public_key->public, secret_key->secret);
 	efree(m);

 	if(rc == 0) {
-		*(c + m_len) = 0x0;
+
+		*(c + m_len) = 0;
 		RETVAL_STRINGL(c + crypto_box_BOXZEROBYTES, m_len - crypto_box_BOXZEROBYTES, 1);
 	}
 	else {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "crypto_box failed: %d", rc);
-		RETVAL_FALSE;
+
+		zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_BOX_FAILED TSRMLS_CC, "crypto_box failed: %d", rc);
+		return;
 	}

 	efree(c);
 }
 /* }}} */

-/* {{{ proto string crytpo::box(string $encrypted_text, string $nonce, string $send_public_key, string $receiver_secret_key)
+/* {{{ proto string crytpo::box_open(string $encrypted_text, nonce $nonce, public_key $sender, secret_key $receiver)
 	Decrypts $encrypted_text with $nonce and keys
 */
 PHP_METHOD(crypto, box_open)
 {
-	unsigned char *m, *c, *encrypted_text, *n, *pk, *sk;
-	int encrypted_text_len, n_len, pk_len, sk_len;
-
-	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssss", &encrypted_text, &encrypted_text_len, &n, &n_len, &pk, &pk_len, &sk, &sk_len) == FAILURE) {
-		RETURN_FALSE;
-	}
-
-	if(encrypted_text_len <= crypto_box_BOXZEROBYTES) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Encrypted text must be at least %d bytes. Actual length is %d bytes", crypto_box_BOXZEROBYTES + 1, encrypted_text_len);
-		RETURN_FALSE;
-	}
-
-	if(n_len != crypto_box_NONCEBYTES) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Nonce length must be %d bytes. Actual length is %d bytes", crypto_box_NONCEBYTES, n_len);
-		RETURN_FALSE;
-	}
-
-	if(pk_len != crypto_box_PUBLICKEYBYTES) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "$receiver_public_key length must be %d bytes. Actual length is %d bytes", crypto_box_PUBLICKEYBYTES, pk_len);
-		RETURN_FALSE;
-	}
-
-	if(sk_len != crypto_box_SECRETKEYBYTES) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "$send_secret_key length must be %d bytes. Actual length is %d bytes", crypto_box_SECRETKEYBYTES, sk_len);
-		RETURN_FALSE;
+	unsigned char *m, *c, *encrypted_text;
+	zval *zn, *zpk, *zsk;
+	int encrypted_text_len;
+	php_sodium_nonce *nonce;
+	php_sodium_key *public_key;
+	php_sodium_key *secret_key;
+
+	PHP_SODIUM_ERROR_HANDLING_INIT()
+	PHP_SODIUM_ERROR_HANDLING_THROW()
+
+	int rc = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sOOO", &encrypted_text, &encrypted_text_len, &zn, php_sodium_nonce_entry, &zpk, php_sodium_public_key_entry, &zsk, php_sodium_secret_key_entry);
+
+	PHP_SODIUM_ERROR_HANDLING_RESTORE()
+
+	if (rc == FAILURE) {
+
+		return;
+	}
+
+	if (encrypted_text_len <= crypto_box_BOXZEROBYTES) {
+
+		zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_BAD_NONCE TSRMLS_CC, "Encrypted text must be at least %d bytes. Actual length is %d bytes", crypto_box_BOXZEROBYTES + 1, encrypted_text_len);
+		return;
+	}
+
+	nonce = (php_sodium_nonce *) zend_object_store_get_object(zn TSRMLS_CC);
+
+	if (! nonce->current) {
+
+		zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_BAD_NONCE TSRMLS_CC, "nonce is missing a current value. Call nonce::next() or nonce::set_nonce()");
+		return;
+	}
+
+	public_key = (php_sodium_key *) zend_object_store_get_object(zpk TSRMLS_CC);
+
+	if (! public_key->public) {
+
+		zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_LOAD_PUBLICKEY TSRMLS_CC, "public_key is missing a key. Call public_key::load()");
+		return;
+	}
+
+	secret_key = (php_sodium_key *) zend_object_store_get_object(zsk TSRMLS_CC);
+
+	if (! secret_key->secret) {
+
+		zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_LOAD_SECRETKEY TSRMLS_CC, "secret_key is missing a key. Call secret_key::load()");
+		return;
 	}

 	int c_len = encrypted_text_len - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES;
 	c = safe_emalloc(c_len, sizeof(unsigned char), 1);
-	memset(c, 0x0, crypto_box_BOXZEROBYTES);
+	memset(c, 0, crypto_box_BOXZEROBYTES);
 	memcpy(c + crypto_box_BOXZEROBYTES, encrypted_text, encrypted_text_len);

 	m = safe_emalloc(c_len + 1, sizeof(unsigned char), 1);
-	int rc = crypto_box(m, c, c_len, n, pk, sk);
+	rc = crypto_box(m, c, c_len, nonce->current, public_key->public, secret_key->secret);
 	efree(c);

 	if(rc == 0) {
-		*(m + c_len) = 0x0;
+
+		*(m + c_len) = 0;
 		RETVAL_STRINGL(crypto_box_ZEROBYTES + m, encrypted_text_len - crypto_box_BOXZEROBYTES, 1);
 	}
 	else {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "crypto_box_open failed: %d", rc);
-		RETVAL_FALSE;
+
+		zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_BOX_OPEN_FAILED TSRMLS_CC, "crypto_box_open failed: %d", rc);
+		return;
 	}

 	efree(m);
@@ -289,7 +499,7 @@
 	b = safe_emalloc(length + 1, sizeof(unsigned char), 1);

 	randombytes(b, length);
-	*(b + length) = 0x0;
+	*(b + length) = 0;
 	RETURN_STRINGL(b, length, 0);
 }
 /* }}} */
@@ -298,21 +508,6 @@
 	ctor */
 PHP_METHOD(nonce, __construct)
 {
-	php_sodium_nonce *intern = PHP_SODIUM_NONCE;
-	unsigned char b[8];
-	php_sodium_nonce_data *d;
-
-	intern->current = safe_emalloc(1, sizeof(php_sodium_nonce_data), 0);
-	memset(intern->current, 0, sizeof(php_sodium_nonce_data));
-	d = (php_sodium_nonce_data *) intern->current;
-	gettimeofday(&d->ts, NULL);
-	//randombytes(d->rand, sizeof(d->rand));
-	d->counter = 0xffffffff;
-
-	size_t newlen;
-	unsigned char *hex = php_bin2hex(intern->current, sizeof(php_sodium_nonce_data), &newlen);
-	php_printf("current: %d %s %d size: %d\n", newlen, hex, __LINE__, sizeof(php_sodium_nonce_data));
-	efree(hex);
 }
 /* }}} */

@@ -323,22 +518,287 @@
 }
 /* }}} */

-/* {{{ proto nonce nonce::increment()
-	Increment nonce by 1 */
-PHP_METHOD(nonce, increment)
+/* {{{ proto nonce nonce::next() */
+PHP_METHOD(nonce, next)
 {
 	php_sodium_nonce *nonce = PHP_SODIUM_NONCE;
-}
-/* }}} */
-
-/* {{{ proto mixed nonce::set_nonce(string $new_nonce])
+
+	if (! nonce->current) {
+		nonce->current = safe_emalloc(crypto_box_NONCEBYTES, sizeof(unsigned char), 1);
+	}
+
+	if (nonce->data) {
+		nonce->data->counter++;
+	}
+	else {
+		nonce->data = safe_emalloc(1, sizeof(php_sodium_nonce_data), 1);
+		randombytes(nonce->data->rand, sizeof(nonce->data->rand));
+		memcpy(nonce->current + 8, nonce->data->rand, 8);
+		nonce->data->counter = 0;
+	}
+
+	lltos(&nonce->data->counter, 8, (nonce->current + 16), 1);
+
+	/* If counter wraparound occurs, get new time() */
+	if (nonce->data->counter == 0) {
+		gettimeofday(&nonce->data->ts, NULL);
+		lltos(&nonce->data->ts.tv_sec, 4, nonce->current, 1);
+		lltos(&nonce->data->ts.tv_usec, 4, nonce->current + 4, 1);
+	}
+
+	unsigned char *hex = php_sodium_hex(nonce->current, crypto_box_NONCEBYTES);
+	zend_update_property_stringl(php_sodium_nonce_entry, getThis(), "current", strlen("current"), hex, (crypto_box_NONCEBYTES * 2) TSRMLS_CC);
+	efree(hex);
+	RETURN_ZVAL(getThis(), 1, 0);
+}
+/* }}} */
+
+/* {{{ proto mixed nonce::set_nonce(string $new_nonce [, bool $affirm_greater = true])
 	  $affirm_greater => if current_nonce < new_nonce, set last_nonce, current_nonce and return nonce object, or return false on current_nonce >= new_nonce
 	! $affirm_greater => set last_nonce = current_nonce, current = new_once, return nonce object
 */
 PHP_METHOD(nonce, set_nonce)
 {
-
-	//if(memcmp() < 0)
+	unsigned char *new_nonce;
+	int new_nonce_len;
+	zend_bool affirm_greater = 1;
+	unsigned char *hex;
+	int rc;
+
+	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &new_nonce, &new_nonce_len, &affirm_greater) == FAILURE) {
+		RETURN_FALSE;
+	}
+
+	if(new_nonce_len != crypto_box_NONCEBYTES) {
+		RETURN_FALSE;
+	}
+
+	php_sodium_nonce *nonce = PHP_SODIUM_NONCE;
+
+	if (affirm_greater) {
+
+		if (nonce->last) {
+
+			/* Compare struct timeval */
+			rc = memcmp(nonce->current, new_nonce, 8);
+
+			if(rc == -1) {
+				RETURN_FALSE;
+			}
+			else if(rc == 0) {
+				/* Compare counter */
+				rc = memcmp(nonce->current + 16, new_nonce + 16, 8);
+
+				if(rc < 1) {
+					RETURN_FALSE;
+				}
+			}
+		}
+	}
+
+	nonce->last = nonce->current;
+	hex = php_sodium_hex(nonce->last, crypto_box_NONCEBYTES);
+	zend_update_property_stringl(php_sodium_nonce_entry, getThis(), "last", strlen("last"), hex, (crypto_box_NONCEBYTES * 2) TSRMLS_CC);
+	efree(hex);
+	nonce->current = estrndup(new_nonce, new_nonce_len);
+	hex = php_sodium_hex(nonce->current, crypto_box_NONCEBYTES);
+	zend_update_property_stringl(php_sodium_nonce_entry, getThis(), "current", strlen("current"), hex, (crypto_box_NONCEBYTES * 2) TSRMLS_CC);
+	efree(hex);
+	RETURN_ZVAL(getThis(), 1, 0);
+}
+/* }}} */
+
+/* {{{ proto public_key::__construct()
+	ctor
+*/
+PHP_METHOD(public_key, __construct) {}
+/* }}} */
+
+/* {{{ proto public_key::__destruct()
+	dtor
+*/
+PHP_METHOD(public_key, __destruct) {}
+/* }}} */
+
+/* {{{ proto mixed public_key::load(string $public_key [, bool $from_hex = true])
+*/
+PHP_METHOD(public_key, load)
+{
+	unsigned char *public_key;
+	int public_key_len;
+	zend_bool from_hex = 1;
+	unsigned char *public_key_bin;
+	int public_key_bin_len;
+
+	PHP_SODIUM_ERROR_HANDLING_INIT()
+	PHP_SODIUM_ERROR_HANDLING_THROW()
+
+	int rc = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &public_key, &public_key_len, &from_hex);
+
+	PHP_SODIUM_ERROR_HANDLING_RESTORE()
+
+	if (rc == FAILURE) {
+
+		return;
+	}
+
+	php_sodium_key *key = PHP_SODIUM_KEY;
+
+	if (from_hex) {
+
+		if (public_key_len != (crypto_box_PUBLICKEYBYTES * 2)) {
+
+			zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_BAD_PUBLICKEY TSRMLS_CC, "Bad public key. Incorrect key length for hex: %d vs %d", public_key_len, (crypto_box_PUBLICKEYBYTES * 2));
+			return;
+		}
+
+		if (key->public) {
+
+			public_key_bin = php_hex2bin(public_key, crypto_box_PUBLICKEYBYTES * 2, &public_key_bin_len);
+			memcpy(key->public, public_key_bin, crypto_box_PUBLICKEYBYTES);
+			efree(public_key_bin);
+		}
+		else {
+
+			key->public = php_hex2bin(public_key, crypto_box_PUBLICKEYBYTES * 2, &public_key_bin_len);
+		}
+	}
+	else {
+
+		if (public_key_len != crypto_box_PUBLICKEYBYTES) {
+
+			zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_BAD_PUBLICKEY TSRMLS_CC, "Bad public key. Incorrect key length: %d vs %d", public_key_len, crypto_box_PUBLICKEYBYTES);
+			return;
+		}
+
+		if (key->public) {
+
+			memcpy(key->public, public_key, crypto_box_PUBLICKEYBYTES);
+		}
+		else {
+
+			key->public = estrndup(public_key, public_key_len);
+		}
+	}
+
+	RETURN_ZVAL(getThis(), 1, 0);
+}
+/* }}} */
+
+/* {{{ proto secret_key::__construct()
+	ctor
+*/
+PHP_METHOD(secret_key, __construct) {}
+/* }}} */
+
+/* {{{ proto secret_key::__destruct()
+	dtor
+*/
+PHP_METHOD(secret_key, __destruct) {}
+/* }}} */
+
+/* {{{ proto mixed secret_key::load(string $public_key, string $secret_key [, bool $from_hex = true])
+*/
+PHP_METHOD(secret_key, load)
+{
+	unsigned char *public_key;
+	int public_key_len;
+	unsigned char *secret_key;
+	int secret_key_len;
+	zend_bool from_hex = 1;
+
+	unsigned char *public_key_bin;
+	int public_key_bin_len;
+	unsigned char *secret_key_bin;
+	int secret_key_bin_len;
+
+	PHP_SODIUM_ERROR_HANDLING_INIT()
+	PHP_SODIUM_ERROR_HANDLING_THROW()
+
+	int rc = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &public_key, &public_key_len, &secret_key, &secret_key_len, &from_hex);
+
+	PHP_SODIUM_ERROR_HANDLING_RESTORE()
+
+	if (rc == FAILURE) {
+
+		return;
+	}
+
+	php_sodium_key *key = PHP_SODIUM_KEY;
+
+	if (from_hex) {
+
+		if (public_key_len != (crypto_box_PUBLICKEYBYTES * 2)) {
+
+			zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_BAD_PUBLICKEY TSRMLS_CC, "Bad public key. Incorrect key length for hex: %d vs %d", public_key_len, (crypto_box_PUBLICKEYBYTES * 2));
+			return;
+		}
+
+		if (secret_key_len != (crypto_box_SECRETKEYBYTES * 2)) {
+
+			zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_BAD_SECRETKEY TSRMLS_CC, "Bad secret key. Incorrect key length for hex: %d vs %d", secret_key_len, (crypto_box_SECRETKEYBYTES * 2));
+			return;
+		}
+
+		public_key_bin = php_hex2bin(public_key, crypto_box_PUBLICKEYBYTES * 2, &public_key_bin_len);
+
+		if (key->public) {
+
+			memcpy(key->public, public_key_bin, crypto_box_PUBLICKEYBYTES);
+			efree(public_key_bin);
+		}
+		else {
+
+			key->public = public_key_bin;
+		}
+
+		secret_key_bin = php_hex2bin(secret_key, crypto_box_SECRETKEYBYTES * 2, &secret_key_bin_len);
+
+		if (key->secret) {
+
+			memcpy(key->secret, secret_key_bin, crypto_box_SECRETKEYBYTES);
+			efree(secret_key_bin);
+		}
+		else {
+
+			key->secret = secret_key_bin;
+		}
+	}
+	else {
+
+		if (public_key_len != crypto_box_PUBLICKEYBYTES) {
+
+			zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_BAD_PUBLICKEY TSRMLS_CC, "Bad public key. Incorrect key length for hex: %d vs %d", public_key_len, crypto_box_PUBLICKEYBYTES);
+			return;
+		}
+
+		if (secret_key_len != crypto_box_SECRETKEYBYTES) {
+
+			zend_throw_exception_ex(php_sodium_crypto_exception_entry, PHP_SODIUM_E_BAD_SECRETKEY TSRMLS_CC, "Bad secret key. Incorrect key length for hex: %d vs %d", secret_key_len, crypto_box_SECRETKEYBYTES);
+			return;
+		}
+
+		if (key->public) {
+
+			memcpy(key->public, public_key, crypto_box_PUBLICKEYBYTES);
+		}
+		else {
+
+			key->public = estrndup(public_key, crypto_box_PUBLICKEYBYTES);
+		}
+
+		if (key->secret) {
+
+			memcpy(key->secret, secret_key, crypto_box_SECRETKEYBYTES);
+		}
+		else {
+
+			key->secret = estrndup(secret_key, secret_key_len);
+		}
+	}
+	zend_update_property_stringl(php_sodium_secret_key_entry, getThis(), "pbin", strlen("pbin"), key->public, crypto_box_PUBLICKEYBYTES TSRMLS_CC);
+	zend_update_property_stringl(php_sodium_secret_key_entry, getThis(), "sbin", strlen("sbin"), key->secret, crypto_box_SECRETKEYBYTES TSRMLS_CC);
+	RETURN_ZVAL(getThis(), 1, 0);
 }
 /* }}} */

@@ -349,42 +809,63 @@
 ZEND_BEGIN_ARG_INFO_EX(ai_sodium_crypto__destruct, 0, 0, 0)
 ZEND_END_ARG_INFO()

-ZEND_BEGIN_ARG_INFO_EX(ai_sodium_crypto_keypair, 0, 0, 2)
-	ZEND_ARG_INFO(1, public_key)
-	ZEND_ARG_INFO(1, secret_key)
+ZEND_BEGIN_ARG_INFO_EX(ai_sodium_crypto_keypair, 0, 0, 0)
 ZEND_END_ARG_INFO()

 ZEND_BEGIN_ARG_INFO_EX(ai_sodium_crypto_box, 0, 0, 4)
 	ZEND_ARG_INFO(0, plain_text)
 	ZEND_ARG_INFO(0, nonce)
-	ZEND_ARG_INFO(0, public_key)
-	ZEND_ARG_INFO(0, secret_key)
+	ZEND_ARG_INFO(0, receiver)
+	ZEND_ARG_INFO(0, sender)
 ZEND_END_ARG_INFO()

 ZEND_BEGIN_ARG_INFO_EX(ai_sodium_crypto_box_open, 0, 0, 4)
 	ZEND_ARG_INFO(0, encrypted_text)
 	ZEND_ARG_INFO(0, nonce)
+	ZEND_ARG_INFO(0, sender)
+	ZEND_ARG_INFO(0, recever)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(ai_sodium_crypto_random_bytes, 0, 0, 1)
+	ZEND_ARG_INFO(0, length)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(ai_sodium_nonce__construct, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(ai_sodium_nonce__destruct, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(ai_sodium_nonce_next, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(ai_sodium_nonce_set_nonce, 0, 0, 1)
+	ZEND_ARG_INFO(0, nonce)
+	ZEND_ARG_INFO(0, affirm_greater)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(ai_sodium_public_key__construct, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(ai_sodium_public_key__destruct, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(ai_sodium_public_key_load, 0, 0, 1)
+	ZEND_ARG_INFO(0, public_key)
+	ZEND_ARG_INFO(0, from_hex)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(ai_sodium_secret_key__construct, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(ai_sodium_secret_key__destruct, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(ai_sodium_secret_key_load, 0, 0, 2)
 	ZEND_ARG_INFO(0, public_key)
 	ZEND_ARG_INFO(0, secret_key)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(ai_sodium_crypto_random_bytes, 0, 0, 1)
-	ZEND_ARG_INFO(0, length)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(ai_sodium_nonce__construct, 0, 0, 0)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(ai_sodium_nonce__destruct, 0, 0, 0)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(ai_sodium_nonce_increment, 0, 0, 0)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(ai_sodium_nonce_set_nonce, 0, 0, 1)
-	ZEND_ARG_INFO(0, nonce)
-ZEND_END_ARG_INFO()
-
+	ZEND_ARG_INFO(0, from_hex)
+ZEND_END_ARG_INFO()
 /* }}} */

 /* {{{ php_sodium_crypto_class_methods[] */
@@ -397,13 +878,30 @@
 	PHP_ME(crypto, random_bytes, ai_sodium_crypto_random_bytes, ZEND_ACC_PUBLIC)
 	{NULL, NULL, NULL}
 };
+/* }}} */

 /* {{{ php_sodium_nonce_class_methods[] */
 static zend_function_entry php_sodium_nonce_class_methods[] = {
 	PHP_ME(nonce, __construct, ai_sodium_nonce__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
 	PHP_ME(nonce, __destruct, ai_sodium_nonce__destruct, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
-	PHP_ME(nonce, increment, ai_sodium_nonce_increment, ZEND_ACC_PUBLIC)
+	PHP_ME(nonce, next, ai_sodium_nonce_next, ZEND_ACC_PUBLIC)
 	PHP_ME(nonce, set_nonce, ai_sodium_nonce_set_nonce, ZEND_ACC_PUBLIC)
+};
+/* }}} */
+
+/* {{{ php_sodium_public_key_methods[] */
+static zend_function_entry php_sodium_public_key_class_methods[] = {
+	PHP_ME(public_key, __construct, ai_sodium_public_key__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
+	PHP_ME(public_key, load, ai_sodium_public_key_load, ZEND_ACC_PUBLIC)
+	PHP_ME(public_key, __destruct, ai_sodium_public_key__destruct, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
+};
+/* }}} */
+
+/* {{{ php_sodium_secret_key_methods[] */
+static zend_function_entry php_sodium_secret_key_class_methods[] = {
+	PHP_ME(secret_key, __construct, ai_sodium_secret_key__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
+	PHP_ME(secret_key, load, ai_sodium_secret_key_load, ZEND_ACC_PUBLIC)
+	PHP_ME(secret_key, __destruct, ai_sodium_secret_key__destruct, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
 };
 /* }}} */

@@ -428,6 +926,11 @@
  */
 PHP_MINIT_FUNCTION(sodium)
 {
+	int i  = 1;
+	char *p = (char *)&i;
+	php_sodium_little_endian = ( (p[0] == 1) ? 1 : 0 );
+	lltos = (php_sodium_little_endian == 1 ? lltos_little: lltos_big);
+
 	zend_class_entry ce_sodium_crypto;
 	INIT_NS_CLASS_ENTRY(ce_sodium_crypto, PHP_SODIUM_NS, "crypto", php_sodium_crypto_class_methods);
 	memcpy(&php_sodium_crypto_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
@@ -438,8 +941,35 @@
 	ce_sodium_nonce.create_object = php_sodium_nonce_ctor;
 	memcpy(&php_sodium_nonce_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
 	php_sodium_nonce_entry = zend_register_internal_class(&ce_sodium_nonce TSRMLS_CC);
-	/*zend_declare_property_null(php_sodium_nonce_entry, "last", strlen("last"), ZEND_ACC_PROTECTED TSRMLS_CC);
-	zend_declare_property_null(php_sodium_nonce_entry, "current", strlen("current"), ZEND_ACC_PROTECTED TSRMLS_CC);*/
+	zend_declare_property_null(php_sodium_nonce_entry, "last", strlen("last"), ZEND_ACC_PROTECTED TSRMLS_CC);
+	zend_declare_property_null(php_sodium_nonce_entry, "current", strlen("current"), ZEND_ACC_PROTECTED TSRMLS_CC);
+
+	zend_class_entry ce_sodium_public_key;
+	INIT_NS_CLASS_ENTRY(ce_sodium_public_key, PHP_SODIUM_NS, "public_key", php_sodium_public_key_class_methods);
+	ce_sodium_public_key.create_object = php_sodium_key_ctor;
+	memcpy(&php_sodium_public_key_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+	php_sodium_public_key_entry = zend_register_internal_class(&ce_sodium_public_key TSRMLS_CC);
+	zend_declare_property_null(php_sodium_public_key_entry, "pbin", strlen("pbin"), ZEND_ACC_PUBLIC TSRMLS_CC);
+
+	zend_class_entry ce_sodium_secret_key;
+	INIT_NS_CLASS_ENTRY(ce_sodium_secret_key, PHP_SODIUM_NS, "secret_key", php_sodium_secret_key_class_methods);
+	ce_sodium_secret_key.create_object = php_sodium_key_ctor;
+	memcpy(&php_sodium_secret_key_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+	php_sodium_secret_key_entry = zend_register_internal_class(&ce_sodium_secret_key TSRMLS_CC);
+	zend_declare_property_null(php_sodium_secret_key_entry, "pbin", strlen("pbin"), ZEND_ACC_PUBLIC TSRMLS_CC);
+	zend_declare_property_null(php_sodium_secret_key_entry, "sbin", strlen("sbin"), ZEND_ACC_PUBLIC TSRMLS_CC);
+
+	zend_class_entry ce_sodium_crypto_exception;
+	INIT_NS_CLASS_ENTRY(ce_sodium_crypto_exception, PHP_SODIUM_NS, "crypto_exception", NULL);
+	php_sodium_crypto_exception_entry = zend_register_internal_class_ex(&ce_sodium_crypto_exception, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC);
+	zend_declare_class_constant_long(php_sodium_crypto_exception_entry, "BAD_NONCE", strlen("BAD_NONCE"), PHP_SODIUM_E_BAD_NONCE TSRMLS_CC);
+	zend_declare_class_constant_long(php_sodium_crypto_exception_entry, "LOAD_PUBLICKEY", strlen("LOAD_PUBLICKEY"), PHP_SODIUM_E_LOAD_PUBLICKEY TSRMLS_CC);
+	zend_declare_class_constant_long(php_sodium_crypto_exception_entry, "LOAD_SECRETKEY", strlen("LOAD_SECRETKEY"), PHP_SODIUM_E_LOAD_SECRETKEY TSRMLS_CC);
+	zend_declare_class_constant_long(php_sodium_crypto_exception_entry, "BAD_PUBLICKEY", strlen("BAD_PUBLICKEY"), PHP_SODIUM_E_BAD_PUBLICKEY TSRMLS_CC);
+	zend_declare_class_constant_long(php_sodium_crypto_exception_entry, "BAD_SECRETKEY", strlen("BAD_SECRETKEY"), PHP_SODIUM_E_BAD_SECRETKEY TSRMLS_CC);
+	zend_declare_class_constant_long(php_sodium_crypto_exception_entry, "KEYPAIR_FAILED", strlen("KEYPAIR_FAILED"), PHP_SODIUM_E_KEYPAIR_FAILED TSRMLS_CC);
+	zend_declare_class_constant_long(php_sodium_crypto_exception_entry, "BOX_FAILED", strlen("BOX_FAILED"), PHP_SODIUM_E_BOX_FAILED TSRMLS_CC);
+	zend_declare_class_constant_long(php_sodium_crypto_exception_entry, "BOX_OPEN_FAILED", strlen("BOX_OPEN_FAILED"), PHP_SODIUM_E_BOX_OPEN_FAILED TSRMLS_CC);

 	return SUCCESS;
 }
@@ -462,6 +992,7 @@
 	php_info_print_table_header(2, "sodium extension version", PHP_SODIUM_VERSION);
 	php_info_print_table_header(2, "sodium library version", sodium_version_string());
 	php_info_print_table_header(2, "randombytes implementation name", randombytes_implementation_name());
+	php_info_print_table_header(2, "endian", (php_sodium_little_endian == 1 ? "little endian" : "big endian"));
 	php_info_print_table_end();
 }
 /* }}} */


fix bug and name

fix bug and name

--- stream.c
+++ stream.c
@@ -246,7 +246,7 @@
 		{
 			int len = (op & 0xf0) >> 4;
 			lua_Integer n = 0;
-			luaL_check(pos + len < size, "read int overflow");
+			luaL_check(pos + len <= size, "read int overflow");
 			memcpy(&n, data + pos, len);
 			correctbytes(&n, len);
 			lua_pushnumber(L, n);
@@ -256,7 +256,7 @@
 		case OP_FLOAT:
 		{
 			int len = (op & 0xf0) >> 4;
-			luaL_check(pos + len < size, "read float or double overflow");
+			luaL_check(pos + len <= size, "read float or double overflow");
 			if (len == sizeof(float))
 			{
 				float n = 0;
@@ -278,10 +278,11 @@
 		{
 			int len = (op & 0xf0) >> 4;
 			size_t n = 0;
+			luaL_check(pos + len <= size, "read string overflow");
 			memcpy(&n, data + pos, len);
 			correctbytes(&n, len);
 			pos += len;
-			luaL_check(pos + n < size, "read string overflow");
+			luaL_check(pos + n <= size, "read string overflow");
 			lua_pushlstring(L, data + pos, n);
 			pos += n;
 			break;
@@ -331,7 +332,7 @@
 	return pos;
 }

-static int lib_new (lua_State *L)
+static int luastream_new (lua_State *L)
 {
 	lua_Stream *self = (lua_Stream *)lua_newuserdata(L, sizeof(lua_Stream));
 	self->buf = buffer_new(BUFF_SIZE);
@@ -342,7 +343,7 @@
 	return 1;
 }

-static int lib_clone (lua_State *L)
+static int luastream_clone (lua_State *L)
 {
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
 	lua_Stream *other = (lua_Stream *)lua_newuserdata(L, sizeof(lua_Stream));
@@ -356,7 +357,7 @@
 	return 1;
 }

-static int lib_extract (lua_State *L)
+static int luastream_extract (lua_State *L)
 {
 	lua_Stream *self, *other;
 	int index = 1;
@@ -381,7 +382,7 @@
 	return 2;
 }

-static int lib_copy (lua_State *L)
+static int luastream_copy (lua_State *L)
 {
 	lua_Stream *self, *other;
 	int index = 1;
@@ -405,7 +406,7 @@
 	return 2;
 }

-static int lib_release (lua_State *L)
+static int luastream_release (lua_State *L)
 {
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
 	if (self->buf)
@@ -413,7 +414,7 @@
 	return 0;
 }

-static int lib_mt_tostring (lua_State *L)
+static int luastream_mt_tostring (lua_State *L)
 {
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
 	if (self->buf)
@@ -423,7 +424,7 @@
 	return 1;
 }

-static int lib_tostring (lua_State *L)
+static int luastream_tostring (lua_State *L)
 {
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
 	if (self->buf)
@@ -433,7 +434,7 @@
 	return 1;
 }

-static int lib_write (lua_State *L)
+static int luastream_write (lua_State *L)
 {
 	size_t pos;
 	int i, top = lua_gettop(L);
@@ -450,7 +451,7 @@
 	return 2;
 }

-static int lib_insert (lua_State *L)
+static int luastream_insert (lua_State *L)
 {
 	int i, top = lua_gettop(L);
 	struct writer_t W;
@@ -479,7 +480,7 @@
 	return 2;
 }

-static int lib_read (lua_State *L)
+static int luastream_read (lua_State *L)
 {
 	struct reader_t R;
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
@@ -495,7 +496,7 @@
 	return nb;
 }

-static int lib_remove (lua_State *L)
+static int luastream_remove (lua_State *L)
 {
 	int top = lua_gettop(L);
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
@@ -507,7 +508,7 @@
 	return 0;
 }

-static int lib_seek (lua_State *L)
+static int luastream_seek (lua_State *L)
 {
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
 	size_t pos = luaL_checkint(L, 2);
@@ -517,7 +518,7 @@
 	return 0;
 }

-static int lib_tell (lua_State *L)
+static int luastream_tell (lua_State *L)
 {
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
 	luaL_check(self->buf, "%s (released) #1", LIB_NAME);
@@ -525,7 +526,7 @@
 	return 1;
 }

-static int lib_unread (lua_State *L)
+static int luastream_unread (lua_State *L)
 {
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
 	luaL_check(self->buf, "%s (released) #1", LIB_NAME);
@@ -533,7 +534,7 @@
 	return 1;
 }

-static int lib_size (lua_State *L)
+static int luastream_size (lua_State *L)
 {
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
 	luaL_check(self->buf, "%s (released) #1", LIB_NAME);
@@ -541,7 +542,7 @@
 	return 1;
 }

-static int lib_empty (lua_State *L)
+static int luastream_empty (lua_State *L)
 {
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
 	if (!self->buf)
@@ -551,7 +552,7 @@
 	return 1;
 }

-static int lib_eof (lua_State *L)
+static int luastream_eof (lua_State *L)
 {
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
 	luaL_check(self->buf, "%s (released) #1", LIB_NAME);
@@ -584,7 +585,7 @@
 	return 0;
 }

-static int lib_writef (lua_State *L)
+static int luastream_writef (lua_State *L)
 {
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
 	size_t len, pos, i = 2;
@@ -681,7 +682,7 @@
 	return 2;
 }

-static int lib_insertf (lua_State *L)
+static int luastream_insertf (lua_State *L)
 {
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
 	size_t len, where, i = 3, pos = luaL_checkint(L, 2);
@@ -799,7 +800,7 @@
 	return 2;
 }

-static int lib_readf (lua_State *L)
+static int luastream_readf (lua_State *L)
 {
 	lua_Stream *self = (lua_Stream *)luaL_checkudata(L, 1, LIB_NAME);
 	size_t len, nb = 0;
@@ -911,29 +912,29 @@
 	return nb;
 }

-static const struct luaL_Reg lib[] = {
-	{"new", lib_new},
-	{"clone", lib_clone},
-	{"extract", lib_extract},
-	{"copy", lib_copy},
-	{"write", lib_write},
-	{"insert", lib_insert},
-	{"read", lib_read},
-	{"remove", lib_remove},
-	{"seek", lib_seek},
-	{"tell", lib_tell},
-	{"unread", lib_unread},
-	{"size", lib_size},
-	{"empty", lib_empty},
-	{"eof", lib_eof},
-	{"writef", lib_writef},
-	{"insertf", lib_insertf},
-	{"readf", lib_readf},
-	{"tostring", lib_tostring},
-	{"release", lib_release},
-	{"__gc", lib_release},
-	{"__tostring", lib_mt_tostring},
-	{"__len", lib_size},
+static const struct luaL_Reg funcs[] = {
+	{"new", luastream_new},
+	{"clone", luastream_clone},
+	{"extract", luastream_extract},
+	{"copy", luastream_copy},
+	{"write", luastream_write},
+	{"insert", luastream_insert},
+	{"read", luastream_read},
+	{"remove", luastream_remove},
+	{"seek", luastream_seek},
+	{"tell", luastream_tell},
+	{"unread", luastream_unread},
+	{"size", luastream_size},
+	{"empty", luastream_empty},
+	{"eof", luastream_eof},
+	{"writef", luastream_writef},
+	{"insertf", luastream_insertf},
+	{"readf", luastream_readf},
+	{"tostring", luastream_tostring},
+	{"release", luastream_release},
+	{"__gc", luastream_release},
+	{"__tostring", luastream_mt_tostring},
+	{"__len", luastream_size},
 	{NULL, NULL}
 };

@@ -942,7 +943,7 @@
 	luaL_newmetatable(L, LIB_NAME);
 	lua_pushvalue(L, -1);
 	lua_setfield(L, -2, "__index");
-	luaL_register(L, NULL, lib);
+	luaL_register(L, NULL, funcs);

 	lua_pushstring(L, "VERSION");
 	lua_pushstring(L, VERSION);


Add comment

Add comment

--- stream.c
+++ stream.c
@@ -5668,6 +5668,7 @@
     }

     if (disable_audio_capturing) {
+      // HLS will not work when video-only, so we add silent audio track.
       audio_channels = 1;
       codec_settings.audio_sample_rate = audio_sample_rate;
       codec_settings.audio_bit_rate = 1000;


Fixing JIRA Issue AXIS2C-1037

Fixing JIRA Issue AXIS2C-1037

git-svn-id: fbb392d5347ebc45c06187f72dfd8bab02595dbf@633091 13f79535-47bb-0310-9956-ffa450edef68

--- util/src/properties.c
+++ util/src/properties.c
@@ -119,7 +119,8 @@
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
     AXIS2_PARAM_CHECK(env->error, key, AXIS2_FAILURE);

-    axutil_hash_set(properties->prop_hash, key, AXIS2_HASH_KEY_STRING, value);
+    axutil_hash_set(properties->prop_hash, axutil_strdup(env, key),
+                    AXIS2_HASH_KEY_STRING, axutil_strdup(env, value));
     return AXIS2_SUCCESS;
 }


space cleanup

space cleanup

--- src/x0/Buffer.h
+++ src/x0/Buffer.h
@@ -219,7 +219,6 @@
 	capacity_(v.capacity_),
 	edit_mode_(v.edit_mode_)
 {
-
 	v.data_ = 0;
 	v.size_ = 0;
 	v.capacity_ = 0;


Fix infinite loop in stress; improve stress

--- stress.c
+++ stress.c
@@ -1,5 +1,6 @@
 #define _GNU_SOURCE
 #include <stdlib.h>
+#include <stdio.h>
 #include <time.h>
 #include "bitboard.h"
 #include "move.h"
@@ -15,6 +16,8 @@
 	Movelist *moves = malloc(sizeof(Movelist));
 	board_init(stress);

+	printf("initial zobrist %.16llx\n", stress->zobrist);
+
 	int cur_move = 0;

 	for (int i = 0; i < max_tests; i++)
@@ -26,13 +29,31 @@
 		cur_move++;

 		if (board_in_check(stress, 1-stress->to_move))
+		{
 			board_undo_move(stress);
+			cur_move--;
+		}

 		if (cur_move == max_moves)
+		{
 			while (cur_move)
+			{
 				board_undo_move(stress);
+				cur_move--;
+			}
+		}
 	}

+	while (cur_move)
+	{
+		board_undo_move(stress);
+		cur_move--;
+	}
+
+	printf("final zobrist %.16llx\n", stress->zobrist);
+
+	free(moves);
 	free(stress);
+
 	return 0;
 }


outas86: Shrink as86_section_names

outas86: Shrink as86_section_names

fix pvs-studio error 'V581 The conditional expressions of the 'if'
operators situated alongside each other are identical.
Check lines: 170, 173.'

Signed-off-by: Martin Lindhe <00944ce1c725c065da4fa2c73a16f47748a35b96@ubique.se>
Signed-off-by: Cyrill Gorcunov <7a1ea01eee6961eb1e372e3508c2670446d086f4@gmail.com>

--- output/outas86.c
+++ output/outas86.c
@@ -167,11 +167,10 @@
     /*
      * Default is 16 bits.
      */
-    if (!name)
+    if (!name) {
         *bits = 16;
-
-    if (!name)
         return stext.index;
+    }

     if (!strcmp(name, ".text"))
         return stext.index;


Handle error return from is_signal_frame

--- src/x86/Gstep.c
+++ src/x86/Gstep.c
@@ -67,6 +67,10 @@
       Debug (13, "dwarf_step() failed (ret=%d), trying frame-chain\n", ret);

       format = unw_is_signal_frame (cursor);
+      if (format < 0) {
+	      Debug (13, "unw_is_signal_frame() failed (ret=%d)\n", ret);
+	      return format;
+      }
       if (format != X86_SCF_NONE)
 	{
 #if defined __linux__


av_write_trailer() must be done before closing codecs.

Patch by aclarke a xuggle d com

git-svn-id: a4d7c1866f8397a4106e0b57fc4fbf792bbdaaaf@17422 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

--- output_example.c
+++ output_example.c
@@ -523,15 +523,18 @@
         }
     }

+    /* write the trailer, if any.  the trailer must be written
+     * before you close the CodecContexts open when you wrote the
+     * header; otherwise write_trailer may try to use memory that
+     * was freed on av_codec_close() */
+    av_write_trailer(oc);
+
     /* close each codec */
     if (video_st)
         close_video(oc, video_st);
     if (audio_st)
         close_audio(oc, audio_st);

-    /* write the trailer, if any */
-    av_write_trailer(oc);
-
     /* free the streams */
     for(i = 0; i < oc->nb_streams; i++) {
         av_freep(&oc->streams[i]->codec);


utils: Don't risk creating a mangled document portal path

I don't know for sure if this code path is reachable when the app id is
set to the empty string, but an extra check can't hurt.

--- src/xdp-utils.c
+++ src/xdp-utils.c
@@ -929,6 +929,9 @@
 {
   int len;

+  if (g_str_equal (app_id, ""))
+    return NULL;
+
   /* If we don't know where the document portal is mounted, then there
    * is no alternate path */
   if (documents_mountpoint == NULL)


Fixes for building on Windows 2000.  Use VS2008 and disabled GDIPLUS/AEROGLASS. These fixes essentially amount to unicode enabling the non-GDI+ code and an #ifdef to not use _dw_composite outside of AEROGLASS sections.

--- win/dw.c
+++ win/dw.c
@@ -3799,17 +3799,17 @@
       }
       if ( stricmp( file + len - 4, ".ico" ) == 0 )
       {
-         *icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
+         *icon = LoadImage(NULL, UTF8toWide(file), IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
          windowtype = BS_ICON;
       }
       else if ( stricmp( file + len - 4, ".bmp" ) == 0 )
       {
-         *hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
+         *hbitmap = (HBITMAP)LoadImage(NULL, UTF8toWide(file), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
          windowtype = BS_BITMAP;
       }
       else if ( stricmp( file + len - 4, ".png" ) == 0 )
       {
-         *hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
+         *hbitmap = (HBITMAP)LoadImage(NULL, UTF8toWide(file), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
          windowtype = BS_BITMAP;
       }
       free(file);
@@ -3820,7 +3820,7 @@
       strcat(file, ".ico");
       if (access(file, 04) == 0)
       {
-         *icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
+         *icon = LoadImage(NULL, UTF8toWide(file), IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
          windowtype = BS_ICON;
       }
       else
@@ -3829,7 +3829,7 @@
          strcat(file, ".bmp");
          if (access(file, 04) == 0)
          {
-            *hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
+            *hbitmap = (HBITMAP)LoadImage(NULL, UTF8toWide(file), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
             windowtype = BS_BITMAP;
          }
       }
@@ -6408,10 +6408,10 @@
             hbitmap = _dw_load_bitmap(file, NULL);
 #else
          if ( len > 1 && data[0] == 'B' && data[1] == 'M' ) /* first 2 chars of data is BM, then its a BMP */
-            hbitmap = (HBITMAP)LoadImage( NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
+            hbitmap = (HBITMAP)LoadImage( NULL, UTF8toWide(file), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
          else /* otherwise its assumed to be an ico */
          {
-            hicon = LoadImage( NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE );
+            hicon = LoadImage( NULL, UTF8toWide(file), IMAGE_ICON, 0, 0, LR_LOADFROMFILE );
             windowtype = BS_ICON;
          }
 #endif
@@ -6802,9 +6802,9 @@
             hbitmap = _dw_load_bitmap(file, NULL);
 #else
             if ( len > 1 && data[0] == 'B' && data[1] == 'M' ) /* first 2 chars of data is BM, then its a BMP */
-               hbitmap = (HBITMAP)LoadImage( NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
+               hbitmap = (HBITMAP)LoadImage( NULL, UTF8toWide(file), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
             else /* otherwise its assumed to be an ico */
-               icon = LoadImage( NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE );
+               icon = LoadImage( NULL, UTF8toWide(file), IMAGE_ICON, 0, 0, LR_LOADFROMFILE );
 #endif
          }
          else
@@ -7136,7 +7136,9 @@
 #ifdef TOOLBAR
       else if(_tcsnicmp(tmpbuf, TOOLBARCLASSNAME, _tcslen(TOOLBARCLASSNAME)+1) == 0)
       {
+#ifdef AEROGLASS
          if(!(_dw_composition && (GetWindowLongPtr(_toplevel_window(box), GWL_EXSTYLE) & WS_EX_LAYERED)))
+#endif
          {
             /* Enable double buffering if our window isn't composited */
             SendMessage(item, TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_DOUBLEBUFFER);
@@ -9068,7 +9070,7 @@
          return 0;
       }
    }
-   icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
+   icon = LoadImage(NULL, UTF8toWide(file), IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
    free(file);
    return (HICN)icon;
 #endif
@@ -9100,7 +9102,7 @@
 #ifdef GDIPLUS
          icon = _dw_load_icon(file);
 #else
-         icon = LoadImage( NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE );
+         icon = LoadImage( NULL, UTF8toWide(file), IMAGE_ICON, 0, 0, LR_LOADFROMFILE );
 #endif
       }
       else
@@ -10581,7 +10583,7 @@
       }
    }

-   pixmap->hbm = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
+   pixmap->hbm = (HBITMAP)LoadImage(NULL, UTF8toWide(file), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    pixmap->depth = _read_bitmap_header(file);
 #endif

@@ -10643,7 +10645,7 @@
 #ifdef GDIPLUS
          pixmap->hbm = _dw_load_bitmap(file, NULL);
 #else
-         pixmap->hbm = (HBITMAP)LoadImage( NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
+         pixmap->hbm = (HBITMAP)LoadImage( NULL, UTF8toWide(file), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
          pixmap->depth = _read_bitmap_header(file);
 #endif
       }


Print ASCII borders in between blocks, and allow them in input files.

--- sudoku.c
+++ sudoku.c
@@ -80,12 +80,26 @@

 static void print_puzzle(Puzzle* solution, Puzzle* init) {
     int size = solution->size;
-    int max_width = 1 + (int) log10(size);
+    int block_size = sqrt(size);
+    int max_cell_width = 1 + (int) log10(size);
     bool highlight_solved_cells = init && isatty(STDOUT_FILENO);
     for (int i = 0; i < size; i++) {
+        if (i > 0 && i % block_size == 0) {
+            for (int j = 0; j < block_size; j++) {
+                if (j > 0)
+                    printf("-|-");
+                for (int k = 0; k < block_size * (1 + max_cell_width) - 1; k++)
+                    printf("-");
+            }
+            printf("\n");
+        }
+
         for (int j = 0; j < size; j++) {
-            if (j > 0)
+            if (j > 0) {
                 printf(" ");
+                if (j % block_size == 0)
+                    printf("| ");
+            }

             int value = solution->cells[i][j];
             if (value == 0)
@@ -95,8 +109,8 @@
                     highlight_solved_cells && init->cells[i][j] == 0;

                 if (highlight_cell)
-                    printf("\x1b[1m");
-                printf("%*d", max_width, value);
+                    printf("\x1b[1;31m");
+                printf("%*d", max_cell_width, value);
                 if (highlight_cell)
                     printf("\x1b[0m");
             }
@@ -154,6 +168,8 @@
             continue;
         }

+        if (buf[strspn(buf, "-|")] == '\0')
+            continue;
         if (cell >= puzzle->num_cells)
             goto err;
         int value;
@@ -345,7 +361,7 @@
     if (config.print_num_solutions)
         printf("%" PRIu64 "\n", dlx_params.num_solutions);
     else if (dlx_params.num_solutions == 0)
-        printf("Puzzle has no solutions.\n");
+        printf("The puzzle has no solutions.\n");

     free_puzzle(&solution);
     free(row_data_start);


Fix xdp_app_info_has_network implementation for snaps

--- src/xdp-utils.c
+++ src/xdp-utils.c
@@ -339,7 +339,9 @@
       break;

     case XDP_APP_INFO_KIND_SNAP:
-      has_network = TRUE; /* FIXME */
+      has_network = g_key_file_get_boolean (app_info->u.snap.keyfile,
+                                            SNAP_METADATA_GROUP_INFO,
+                                            SNAP_METADATA_KEY_NETWORK, NULL);
       break;

     case XDP_APP_INFO_KIND_HOST:


Added 'mode' field to OWPPerConnDataRec struct.

git-svn-id: a387e899ed10e03ab636af3ac21b4488e15ce2f7@268 a2d82226-602c-0410-bba7-e51b83dd10d2

--- owamp/conndata.h
+++ owamp/conndata.h
@@ -35,6 +35,7 @@
 	policy_data       *policy;              /* global policy hash */
 	owp_tree_node_ptr node;                 /* node for the connection
 						   class */
+	int               mode                  /* control connection mode */
 } OWPPerConnDataRec, *OWPPerConnData;

 #endif	/*	_OWP_CONNDATA_H	*/


msm8610: add three type subtype support

msm8610: add three type subtype support

Add subtype support for SKUF SKUAA SKUAB

Change-Id: I61566293c25713d20b1cdb4c5f872d32919404ed

--- target/msm8610/init.c
+++ target/msm8610/init.c
@@ -48,6 +48,12 @@

 #define TLMM_VOL_UP_BTN_GPIO    72

+enum target_subtype {
+	HW_PLATFORM_SUBTYPE_SKUAA = 1,
+	HW_PLATFORM_SUBTYPE_SKUF = 2,
+	HW_PLATFORM_SUBTYPE_SKUAB = 3,
+};
+
 static uint32_t mmc_sdc_base[] =
 	{ MSM_SDC1_BASE, MSM_SDC2_BASE };

@@ -151,6 +157,12 @@
 	switch(platform_subtype)
 	{
 	case HW_PLATFORM_SUBTYPE_UNKNOWN:
+		break;
+	case HW_PLATFORM_SUBTYPE_SKUAA:
+		break;
+	case HW_PLATFORM_SUBTYPE_SKUF:
+		break;
+	case HW_PLATFORM_SUBTYPE_SKUAB:
 		break;
 	default:
 		dprintf(CRITICAL, "Platform Subtype : %u is not supported\n", platform_subtype);


Fixed tests

Fixed tests

--- utils/src/test/time.c
+++ utils/src/test/time.c
@@ -24,10 +24,10 @@

 AVS_UNIT_TEST(time, time_from_ms) {
     struct timespec value;
-    avs_time_from_ms(&value, 1234);
+    value = avs_time_from_ms(1234);
     AVS_UNIT_ASSERT_EQUAL(value.tv_sec, 1);
     AVS_UNIT_ASSERT_EQUAL(value.tv_nsec, 234000000L);
-    avs_time_from_ms(&value, -1234);
+    value = avs_time_from_ms(-1234);
     AVS_UNIT_ASSERT_EQUAL(value.tv_sec, -2);
     AVS_UNIT_ASSERT_EQUAL(value.tv_nsec, 766000000L);
 }
@@ -63,56 +63,56 @@

 AVS_UNIT_TEST(time, div_ns_only) {
     struct timespec value = { 0, 10 };
-    avs_time_div(&value, &value, 2);
+    value = avs_time_div(&value, 2);
     AVS_UNIT_ASSERT_EQUAL(value.tv_sec, 0);
     AVS_UNIT_ASSERT_EQUAL(5, value.tv_nsec);
 }

 AVS_UNIT_TEST(time, div) {
     struct timespec value = { 1, 10 };
-    avs_time_div(&value, &value, 2);
+    value = avs_time_div(&value, 2);
     AVS_UNIT_ASSERT_EQUAL(value.tv_sec, 0);
     AVS_UNIT_ASSERT_EQUAL(value.tv_nsec, 500 * 1000 * 1000 + 5);
 }

 AVS_UNIT_TEST(time, div_s_rest) {
     struct timespec value = { 3, 500 * 1000 * 1000 };
-    avs_time_div(&value, &value, 2);
+    value = avs_time_div(&value, 2);
     AVS_UNIT_ASSERT_EQUAL(value.tv_sec, 1);
     AVS_UNIT_ASSERT_EQUAL(value.tv_nsec, 750 * 1000 * 1000);
 }

 AVS_UNIT_TEST(time, div_big_divisor) {
     struct timespec value = { 1, 0 };
-    avs_time_div(&value, &value, 1 * 1000 * 1000 * 1000);
+    value = avs_time_div(&value, 1 * 1000 * 1000 * 1000);
     AVS_UNIT_ASSERT_EQUAL(value.tv_sec, 0);
     AVS_UNIT_ASSERT_EQUAL(value.tv_nsec, 1);
 }

 AVS_UNIT_TEST(time, div_big_seconds) {
     struct timespec value = { 999 * 1000 * 1000, 0 };
-    avs_time_div(&value, &value, 1 * 1000 * 1000 * 1000);
+    value = avs_time_div(&value, 1 * 1000 * 1000 * 1000);
     AVS_UNIT_ASSERT_EQUAL(value.tv_sec, 0);
     AVS_UNIT_ASSERT_EQUAL(value.tv_nsec, 999 * 1000 * 1000);
 }

 AVS_UNIT_TEST(time, div_negative) {
     struct timespec value = { -1, 0 };
-    avs_time_div(&value, &value, 2);
+    value = avs_time_div(&value, 2);
     AVS_UNIT_ASSERT_EQUAL(value.tv_sec, -1);
     AVS_UNIT_ASSERT_EQUAL(value.tv_nsec, 500 * 1000 * 1000);
 }

 AVS_UNIT_TEST(time, div_negative_ns) {
     struct timespec value = { -1, 500 * 1000 * 1000 };
-    avs_time_div(&value, &value, 2);
+    value = avs_time_div(&value, 2);
     AVS_UNIT_ASSERT_EQUAL(value.tv_sec, -1);
     AVS_UNIT_ASSERT_EQUAL(value.tv_nsec, 750 * 1000 * 1000);
 }

 AVS_UNIT_TEST(time, div_big_negative) {
     struct timespec value = { -999 * 1000 * 1000, 0 };
-    avs_time_div(&value, &value, 1 * 1000 * 1000 * 1000);
+    value = avs_time_div(&value, 1 * 1000 * 1000 * 1000);
     AVS_UNIT_ASSERT_EQUAL(value.tv_sec, -1);
     AVS_UNIT_ASSERT_EQUAL(value.tv_nsec, 1 * 1000 * 1000);
 }


remove_warning in db.c

remove_warning in db.c

--- src/db.c
+++ src/db.c
@@ -450,8 +450,8 @@
     list *keys = listCreate();
     listNode *node, *nextnode;
     long count = 10;
-    sds pat;
-    int patlen, use_pattern = 0;
+    sds pat = NULL;
+    int patlen = 0, use_pattern = 0;
     dict *ht;

     /* Object must be NULL (to iterate keys names), or the type of the object


Basic handling for the scrolled widget.  Scrollbox now works on Windows.

--- win/dw.c
+++ win/dw.c
@@ -1369,14 +1369,22 @@
             }
             else if(strncmp(tmpbuf, ScrollClassName, strlen(ScrollClassName)+1)==0)
             {
-                /* Then try the bottom or right box */
+                /* Handle special case of scrollbox */
                 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA);
                 int cx = width + vectorx;
                 int cy = height + vectory;
                 int usedx = 0, usedy = 0, usedpadx = 0, usedpady = 0, depth = 0;
                 Box *thisbox = (Box *)GetWindowLongPtr(cinfo->combo, GWLP_USERDATA);
+                SCROLLINFO hsi, vsi;
                 RECT rect;

+                vsi.cbSize = hsi.cbSize = sizeof(SCROLLINFO);
+                vsi.fMask = hsi.fMask = SIF_POS;
+
+                /* Save the current scroll positions */
+                GetScrollInfo(handle, SB_HORZ, &hsi);
+                GetScrollInfo(handle, SB_VERT, &vsi);
+
                 /* Position the scrollbox */
                 MoveWindow(handle, currentx + pad, currenty + pad, cx, cy, FALSE);

@@ -1398,7 +1406,29 @@
                 }

                 /* Position the scrolled box */
-                MoveWindow(cinfo->combo, 0, 0, cx, cy, FALSE);
+                vsi.fMask = hsi.fMask = SIF_POS | SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL;
+                vsi.nMin = hsi.nMin = vsi.nMax = hsi.nMax = 0;
+                if(rect.bottom < usedy)
+                {
+                    vsi.nMax = usedy;
+                    vsi.nPage = rect.bottom;
+                    if(vsi.nPos > vsi.nMax)
+                    {
+                        vsi.nPos = vsi.nMax;
+                    }
+                }
+                if(rect.right < usedx)
+                {
+                    hsi.nMax = usedx;
+                    hsi.nPage = rect.right;
+                    if(hsi.nPos > hsi.nMax)
+                    {
+                        hsi.nPos = hsi.nMax;
+                    }
+                }
+                MoveWindow(cinfo->combo, -hsi.nPos, -vsi.nPos, cx, cy, FALSE);
+                SetScrollInfo(handle, SB_HORZ, &hsi, TRUE);
+                SetScrollInfo(handle, SB_VERT, &vsi, TRUE);

                 /* Layout the content of the scrollbox */
                 _do_resize(thisbox, cx, cy);
@@ -1514,27 +1544,16 @@
 int _HandleScroller(HWND handle, int bar, int pos, int which)
 {
    SCROLLINFO si;
-#ifndef SCROLLBOX_DEBUG
-char lasterror[257];
-#endif

    ZeroMemory( &si, sizeof(si) );
    si.cbSize = sizeof(SCROLLINFO);
    si.fMask = SIF_ALL;

    SendMessage(handle, SBM_GETSCROLLINFO, 0, (LPARAM)&si);
-#ifndef SCROLLBOX_DEBUG
-FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT), lasterror, 256, NULL);
-_dw_log( "Error from SendMessage in _HandleScroller: Handle %x Bar %s(%d) Which %d: %s", handle, (bar==SB_HORZ)?"HORZ" : "VERT", bar, which,lasterror );
-#endif

    ZeroMemory( &si, sizeof(si) );
    si.cbSize = sizeof(SCROLLINFO);
    si.fMask = SIF_ALL;
-#ifndef SCROLLBOX_DEBUG
-GetScrollInfo( handle, bar, &si );
-_dw_log( "Error from GetScrollInfo in _HandleScroller: Handle %x Bar %s(%d) Which %d: %s", handle, (bar==SB_HORZ)?"HORZ" : "VERT", bar, which,lasterror );
-#endif

    switch(which)
    {
@@ -3215,12 +3234,64 @@
 {
    switch (msg)
    {
-   case WM_HSCROLL:
-   case WM_VSCROLL:
-      {
-         HWND handle = (HWND)mp2;
-      }
-      break;
+       case WM_HSCROLL:
+       case WM_VSCROLL:
+       {
+            ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+            SCROLLINFO hsi, vsi, *si = &hsi;
+            int bar = SB_HORZ;
+            int which = LOWORD(mp1);
+
+            vsi.cbSize = hsi.cbSize = sizeof(SCROLLINFO);
+            vsi.fMask = hsi.fMask = SIF_POS | SIF_RANGE;
+
+            /* Save the current scroll positions */
+            GetScrollInfo(hwnd, SB_HORZ, &hsi);
+            GetScrollInfo(hwnd, SB_VERT, &vsi);
+
+            if(msg == WM_VSCROLL)
+            {
+                bar = SB_VERT;
+                si = &vsi;
+            }
+
+            switch(which)
+            {
+            case SB_THUMBTRACK:
+                si->nPos = HIWORD(mp1);
+                break;
+            /*case SB_PAGEDOWN:*/
+            case SB_PAGELEFT:
+                si->nPos = si->nPos - si->nPage;
+                if(si->nPos < 0)
+                    si->nPos = 0;
+                break;
+            /*case SB_PAGEUP:*/
+            case SB_PAGERIGHT:
+                si->nPos = si->nPos + si->nPage;
+                if(si->nPos > (si->nMax - si->nPage) + 1)
+                    si->nPos = (si->nMax - si->nPage) + 1;
+                break;
+            /*case SB_LINEDOWN:*/
+            case SB_LINELEFT:
+                si->nPos = si->nPos - 1;
+                if(si->nPos < si->nMin)
+                    si->nPos = si->nMin;
+                break;
+            /*case SB_LINEUP:*/
+            case SB_LINERIGHT:
+                si->nPos = si->nPos + 1;
+                if(si->nPos > (si->nMax - si->nPage) + 1)
+                    si->nPos = (si->nMax - si->nPage) + 1;
+                break;
+            }
+
+            /* Position the scrolled box */
+            vsi.fMask = hsi.fMask = SIF_POS | SIF_DISABLENOSCROLL;
+            SetWindowPos(cinfo->combo, 0, -hsi.nPos, -vsi.nPos, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
+            SetScrollInfo(hwnd, bar, si, TRUE);
+       }
+       break;
    }
    return DefWindowProc(hwnd, msg, mp1, mp2);
 }


msm8916: Correct the max clk frequency for SDC1 and SDC2 controllers.

HW Team recommended a stable SDC1 clk frequency of 177MHZ
and SDC2 clk frequency of 200MHZ in HS200 Mode.
Correct the frequencies accordingly.

CRs-Fixed: 636361
Change-Id: I6ea35b7b11ea171f1f6847bf7490955e0f4f96df

--- target/msm8916/init.c
+++ target/msm8916/init.c
@@ -76,7 +76,7 @@
 	set_sdc_power_ctrl();

 	config.bus_width = DATA_BUS_WIDTH_8BIT;
-	config.max_clk_rate = MMC_CLK_200MHZ;
+	config.max_clk_rate = MMC_CLK_177MHZ;

 	/* Try slot 1*/
 	config.slot         = 1;
@@ -88,6 +88,7 @@
 	if (!(dev = mmc_init(&config))) {
 	/* Try slot 2 */
 		config.slot         = 2;
+		config.max_clk_rate = MMC_CLK_200MHZ;
 		config.sdhc_base    = mmc_sdhci_base[config.slot - 1];
 		config.pwrctl_base  = mmc_pwrctl_base[config.slot - 1];
 		config.pwr_irq      = mmc_sdc_pwrctl_irq[config.slot - 1];


fixed compile error on FreeBSD.

fixed compile error on FreeBSD.

--- swoole.c
+++ swoole.c
@@ -1213,7 +1213,7 @@

 PHP_FUNCTION(swoole_get_local_mac)
 {
-#ifndef __MACH__
+#ifdef SIOCGIFHWADDR
     struct ifconf ifc;
     struct ifreq buf[16];
     char mac[32] = {0};
@@ -1249,10 +1249,10 @@
             i++;
         }
     }
-
     close(sock);
 #else
-
+    php_error_docref(NULL TSRMLS_CC, E_WARNING, "swoole_get_local_mac is not supported.");
+    RETURN_FALSE;
 #endif
 }


Moved the used xmms_output_t into xmms_main_t.
Implemented the destructor for xmms_main_t which fixes a memory leak.

BK KEY: tilman@code-monkey.de|ChangeSet|20040919150612|20279

--- src/xmms/main.c
+++ src/xmms/main.c
@@ -66,6 +66,7 @@

 struct xmms_main_St {
 	xmms_object_t object;
+	xmms_output_t *output;
 };

 typedef struct xmms_main_St xmms_main_t;
@@ -111,9 +112,12 @@
 }

 static void
-quit (xmms_object_t *object, xmms_error_t *error)
-{
+xmms_main_destroy (xmms_object_t *object)
+{
+	xmms_main_t *mainobj = (xmms_main_t *) object;
 	gchar filename[XMMS_MAX_CONFIGFILE_LEN];
+
+	xmms_object_unref (mainobj->output);

 	g_snprintf (filename, XMMS_MAX_CONFIGFILE_LEN, "%s/.xmms2/xmms2.conf", g_get_home_dir ());
 	xmms_config_save (filename);
@@ -123,6 +127,12 @@
 	xmms_medialib_shutdown ();
 	xmms_plugin_shutdown ();
 	xmms_log_shutdown ();
+}
+
+static void
+quit (xmms_object_t *object, xmms_error_t *error)
+{
+	xmms_object_unref (object);

 	exit (EXIT_SUCCESS);
 }
@@ -134,7 +144,6 @@
 {
 	xmms_plugin_t *o_plugin;
 	xmms_config_value_t *cv;
-	xmms_output_t *output;
 	xmms_main_t *mainobj;

 	int opt;
@@ -236,13 +245,15 @@
 	o_plugin = xmms_output_find_plugin (outname);
 	g_return_val_if_fail (o_plugin, -1);

-	output = xmms_output_new (o_plugin);
-	g_return_val_if_fail (output, -1);
-
-	xmms_output_playlist_set (output, playlist);
+	mainobj = xmms_object_new (xmms_main_t, xmms_main_destroy);
+
+	mainobj->output = xmms_output_new (o_plugin);
+	g_return_val_if_fail (mainobj->output, -1);
+
+	xmms_output_playlist_set (mainobj->output, playlist);

 	xmms_medialib_init ();
-	xmms_medialib_output_register (output);
+	xmms_medialib_output_register (mainobj->output);

 	g_snprintf (default_path, sizeof (default_path),
 	            "unix:path=/tmp/xmms-dbus-%s", g_get_user_name ());
@@ -253,7 +264,6 @@

 	xmms_signal_init ();

-	mainobj = xmms_object_new (xmms_main_t, NULL);
 	xmms_dbus_register_object ("main", XMMS_OBJECT (mainobj));
 	xmms_object_method_add (XMMS_OBJECT (mainobj), XMMS_METHOD_QUIT, XMMS_METHOD_FUNC (quit));


TTL command fixed to work reliably with diskstore

--- src/db.c
+++ src/db.c
@@ -592,6 +592,7 @@
 void ttlCommand(redisClient *c) {
     time_t expire, ttl = -1;

+    if (server.ds_enabled) lookupKeyRead(c->db,c->argv[1]);
     expire = getExpire(c->db,c->argv[1]);
     if (expire != -1) {
         ttl = (expire-time(NULL));


target: msm8916: Enable charger mode check

Check the boot reason to determine whether need to boot
into charger mode.

Change-Id: I3eac21269c34c768f45381d7982aec6e74c47cd6

--- target/msm8916/init.c
+++ target/msm8916/init.c
@@ -362,6 +362,26 @@
         splash_override = override;
 }

+unsigned target_pause_for_battery_charge(void)
+{
+	uint8_t pon_reason = pm8x41_get_pon_reason();
+	uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
+	dprintf(INFO, "%s : pon_reason is %d cold_boot:%d\n", __func__,
+		pon_reason, is_cold_boot);
+	/* In case of fastboot reboot,adb reboot or if we see the power key
+	* pressed we do not want go into charger mode.
+	* fastboot reboot is warm boot with PON hard reset bit not set
+	* adb reboot is a cold boot with PON hard reset bit set
+	*/
+	if (is_cold_boot &&
+			(!(pon_reason & HARD_RST)) &&
+			(!(pon_reason & KPDPWR_N)) &&
+			((pon_reason & USB_CHG) || (pon_reason & DC_CHG)))
+		return 1;
+	else
+		return 0;
+}
+
 void target_usb_stop(void)
 {
 	/* Disable VBUS mimicing in the controller. */


set sans-24 as the default font name

set sans-24 as the default font name

--- sxlock.c
+++ sxlock.c
@@ -286,7 +286,7 @@
                     "   -l: derange the password length indicator\n"
                     "   -d: do not handle DPMS\n"
                     "   -p passchars: characters used to obfuscate the password\n"
-                    "   -f font: X logical font description\n"
+                    "   -f font name (fontconfig pattern string\n"
                     "   -u username: user name to show\n"
                 );
                 break;
@@ -339,7 +339,7 @@

     /* set default values for command-line arguments */
     opt_passchar = "*";
-    opt_font = "-misc-fixed-medium-r-*--17-120-*-*-*-*-iso8859-1";
+    opt_font = "sans-24";
     opt_username = username;
     opt_hidelength = False;
     opt_usedpms = True;
@@ -367,7 +367,7 @@
         die("cannot open dpy\n");

     if (!(font = XftFontOpenName(dpy, DefaultScreen(dpy), opt_font)))
-        die("error: could not find font. Try using a full description.\n");
+        die("error: Xft could not open font %s.\n", opt_font);

     screen_num = DefaultScreen(dpy);
     root = DefaultRootWindow(dpy);


BUG(391): Fix crash on bad options to xmms2d.

--- src/xmms/main.c
+++ src/xmms/main.c
@@ -352,6 +352,7 @@
 		{"version", 0, NULL, 'V'},
 		{"help", 0, NULL, 'h'},
 		{"conf", 1, NULL, 'c'},
+		{NULL,}
 	};

 	memset (&signals, 0, sizeof (sigset_t));


fixed valgrind warning (overlapping memcmp)

git-svn-id: 0126ed97fe24b68ac16df8f15bac817fed1c5b9f@1349 66673985-dd14-0410-9433-caba4d15c716

--- src/db.c
+++ src/db.c
@@ -317,8 +317,8 @@
             return (db_set_error(db, HAM_OUT_OF_MEMORY));
         }
     }
-    memcpy(ext_key->data, key_data, db_get_keysize(db)-sizeof(ham_offset_t));
-    memcpy(ext_key->data+(db_get_keysize(db)-sizeof(ham_offset_t)),
+    memmove(ext_key->data, key_data, db_get_keysize(db)-sizeof(ham_offset_t));
+    memcpy (ext_key->data+(db_get_keysize(db)-sizeof(ham_offset_t)),
                record.data, record.size);

     /* insert the FULL key in the cache */


target: msm8952: Set rclk as pull down

target: msm8952: Set rclk as pull down

Set the rclk tlmm pin as pull down

Change-Id: I6713d12a4543aaed9f86a05842fd30676fd6b7cf

--- target/msm8952/init.c
+++ target/msm8952/init.c
@@ -111,9 +111,15 @@
 		{ SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, 0},
 	};

+	struct tlmm_cfgs sdc1_rclk_cfg[] =
+	{
+		{ SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, 0},
+	};
+
 	/* Set the drive strength & pull control values */
 	tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
 	tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
+	tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
 }

 void target_sdc_init()


Cleanup

Cleanup

--- symbol.c
+++ symbol.c
@@ -4,12 +4,15 @@
     date    : 07/19/19
 */
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
 #include "stack.h"
 #include "builtin.h"
-#define calloc(N,Z)	GC_MALLOC((N)*(Z))
-#define malloc(Z)	GC_MALLOC(Z)
-#define realloc(P,Z)	GC_REALLOC(P,Z)
-#define free(P)
+#define kcalloc(N,Z)	GC_MALLOC((N)*(Z))
+#define kmalloc(Z)	GC_MALLOC(Z)
+#define krealloc(P,Z)	GC_REALLOC(P,Z)
+#define kfree(P)
 #include "khash.h"

 				/* builtin.c */


Added error handling for invalid integer arguments.

--- src/xrestrict.c
+++ src/xrestrict.c
@@ -225,10 +225,24 @@
 			}
 		} else {
 			if (parsing_state == PARSE_DEVICEID) {
-				device_id = atoi(argv[i]);
+				char * invalid;
+				device_id = strtoul(argv[i], &invalid, 10);
+				if (invalid && *invalid != '\0') {
+					fprintf(stderr, "Failed to parse device id \"%s\".\n", argv[i]);
+					print_usage(argv[0]);
+					XCloseDisplay(display);
+					return -1;
+				}
 				parsing_state = PARSE_NONE;
 			} else if (parsing_state == PARSE_CRTCINDEX) {
-				crtc_index = atoi(argv[i]);
+				char * invalid;
+				crtc_index = strtoul(argv[i], &invalid, 10);
+				if (invalid && *invalid != '\0') {
+					fprintf(stderr, "Failed to parse crtc index \"%s\".\n", argv[i]);
+					print_usage(argv[0]);
+					XCloseDisplay(display);
+					return -1;
+				}
 				parsing_state = PARSE_NONE;
 			} else {
 				XCloseDisplay(display);